home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4299 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.4 KB  |  42 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!iWarp.intel.com|ichips!sedona!bhoughto
  3. From: bhoughto@sedona.intel.com (Blair P. Houghton)
  4. Subject: Re: A regexp quickie
  5. Message-ID: <1992Aug14.161834.8226@ichips.intel.com>
  6. Keywords: regexp.
  7. Sender: news@ichips.intel.com (News Account)
  8. Organization: Intel Corp., Chandler, Arizona
  9. References: <BsyqJs.HIz@cck.coventry.ac.uk>
  10. Date: Fri, 14 Aug 1992 16:18:34 GMT
  11. Lines: 29
  12.  
  13. In article <BsyqJs.HIz@cck.coventry.ac.uk> ccx018@cch.coventry.ac.uk (Leslie Griffiths (Griff)) writes:
  14. >Its easy to express either of these
  15. >/^.*[     ]*/
  16. >and
  17. >/[     ][     ]*.*[     ][     ]*/
  18. >But how would one express both in a regexp.
  19. >NOTE - I am using sed, so no full regexps, no | or +
  20.  
  21. sed is a cumulative process on a line.  Do like so:
  22.  
  23.     sed -e '/^.*[  ]*/...' -e '>/[     ][      ]*.*[   ][      ]*/...'
  24.  
  25. (where '...' is the action to be performed)
  26.  
  27. However, your second pattern doesn't do the job.  It
  28. gets the longest string matching the pattern, which
  29. includes all words between the first and last whitespace
  30. characters on the line.  For instance, between these two
  31. upcarets:^                                           ^
  32.  
  33. Come to look at it, your first pattern has the same
  34. problem; it matches everything up to the last word on the
  35. line.
  36.  
  37. You want to omit whitespace from the inner part of the pattern.
  38. sed -e '/^[^     ]*[    ]*/...' -e '/[     ]*[^    ]*[     ]*/...'
  39.  
  40.                 --Blair
  41.                   "Slam-bam-RTFM..."
  42.