home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- 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
- From: lhjensen@fish.Princeton.EDU (Leif Jensen)
- Subject: Re: searching a file
- Message-ID: <1993Jan4.015530.23571@Princeton.EDU>
- Originator: news@nimaster
- Sender: news@Princeton.EDU (USENET News System)
- Nntp-Posting-Host: fish.princeton.edu
- Organization: Princeton University
- References: <1993Jan3.021839.10462@mnemosyne.cs.du.edu> <1993Jan03.070721.14178@jpradley.jpr.com>
- Date: Mon, 4 Jan 1993 01:55:30 GMT
- Lines: 33
-
- In article <1993Jan03.070721.14178@jpradley.jpr.com> jpr@jpradley.jpr.com (Jean-Pierre Radley) writes:
- >Here's a command to print all words in /usr/dict/words having 1, 2 or 3 "l"s:
- >
- ></usr/dict/words tr '[A-Z]' '[a-z]' |
- >sed -n '
- >/^\([^l]*l[^l]*\)\1\{0,2\}$/p
- >'
-
- Here is a method using awk:
-
- awk -Fl 'NF >= 2 && NF <= 4' < /usr/dict/words
-
- Actually, I *think* your sed command is invalid. (Your tr command
- also needlessly includes '[' and ']'.) The man page says "A
- one-character RE followed by \{m\}, \{m,\}, or \{m,n\} ...." I do not
- think \1 can be followed by \{0,2\}. The \{\} construction is also not
- present in all versions of sed. Anyway, your RE wouldn't do quite
- what you think. '^\([^l]*l\)\1$' matches not lines with exactly two
- l's, but only lines of the form alal, where "a" is any sequence of
- characters not containing 'l' or newline and "l" is a literal 'l'. A
- regular expression like '^\([^l]*l[^l]*\)\1$' matches only lines of the
- form "albalb". The easiest way to do what you wanted using sed is to
- use the command:
-
- sed -n '/^[^l]*l[^l]*$/p
- /^[^l]*l[^l]*l[^l]*$/p
- /^[^l]*l[^l]*l[^l]*l[^l]*$/p' /usr/dict/words
-
- Hope this helps,
-
- --
- lhjensen@phoenix.princeton.edu
- Leif Jensen
-