home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / question / 15134 < prev    next >
Encoding:
Text File  |  1993-01-03  |  1.8 KB  |  47 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!jvnc.net!princeton!fish.Princeton.EDU!lhjensen
  3. From: lhjensen@fish.Princeton.EDU (Leif Jensen)
  4. Subject: Re: searching a file
  5. Message-ID: <1993Jan4.015530.23571@Princeton.EDU>
  6. Originator: news@nimaster
  7. Sender: news@Princeton.EDU (USENET News System)
  8. Nntp-Posting-Host: fish.princeton.edu
  9. Organization: Princeton University
  10. References: <1993Jan3.021839.10462@mnemosyne.cs.du.edu> <1993Jan03.070721.14178@jpradley.jpr.com>
  11. Date: Mon, 4 Jan 1993 01:55:30 GMT
  12. Lines: 33
  13.  
  14. In article <1993Jan03.070721.14178@jpradley.jpr.com> jpr@jpradley.jpr.com (Jean-Pierre Radley) writes:
  15. >Here's a command to print all words in /usr/dict/words having 1, 2 or 3 "l"s:
  16. >
  17. ></usr/dict/words tr '[A-Z]' '[a-z]' |
  18. >sed -n '
  19. >/^\([^l]*l[^l]*\)\1\{0,2\}$/p
  20. >'
  21.  
  22. Here is a method using awk:
  23.  
  24. awk -Fl 'NF >= 2 && NF <= 4' < /usr/dict/words
  25.  
  26. Actually, I *think* your sed command is invalid.  (Your tr command
  27. also needlessly includes '[' and ']'.) The man page says "A
  28. one-character RE followed by \{m\}, \{m,\}, or \{m,n\} ...."  I do not
  29. think \1 can be followed by \{0,2\}.  The \{\} construction is also not
  30. present in all versions of sed.  Anyway, your RE wouldn't do quite
  31. what you think.  '^\([^l]*l\)\1$' matches not lines with exactly two
  32. l's, but only lines of the form alal, where "a" is any sequence of
  33. characters not containing 'l' or newline and "l" is a literal 'l'.  A
  34. regular expression like '^\([^l]*l[^l]*\)\1$' matches only lines of the
  35. form "albalb".  The easiest way to do what you wanted using sed is to
  36. use the command:
  37.  
  38. sed -n '/^[^l]*l[^l]*$/p
  39. /^[^l]*l[^l]*l[^l]*$/p
  40. /^[^l]*l[^l]*l[^l]*l[^l]*$/p' /usr/dict/words
  41.  
  42. Hope this helps,
  43.  
  44. --
  45. lhjensen@phoenix.princeton.edu
  46. Leif Jensen
  47.