home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
- From: navarra@casbah.acns.nwu.edu (John Navarra)
- Subject: Regular Expressions with [fe]grep (AGAIN)
- Message-ID: <1992Jul30.110331.3647@news.acns.nwu.edu>
- Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
- Organization: Northwestern University, Evanston Illinois.
- Date: Thu, 30 Jul 1992 11:03:31 GMT
- Lines: 78
-
- [no one provided a useful answer the first time I tried this so I will
- try again]
-
- I have two related questions on regular expressions using some form of
- grep. They both involve grouping the pattern with ()'s and doing some
- form of counting of the number of occurences of the pattern within
- the paranthesis.
-
-
- Say I have the following file:
-
- 0
- 00
- 000
- 0000
- 00000
- 000000
- 0000000
- ...
-
- and I issue the following commands:
-
- $ grep '^0\{1\}$' testfile
- 0
- $ grep '^0\{2\}$' testfile
- 00
- $ grep '^0\{1,3\}$' testfile
- 0
- 00
- 000
-
- Now, however, I want to change each '0' to a '123':
-
- 123
- 123123
- 123123123
- 123123123123
- 123123123123123
- 123123123123123123
- 123123123123123123123
-
- and I want to get the same results with the pattern matching.
- I want to print out the lines with one string of '123', the
- lines with two strings of '123', or at least 1 but no more than
- 3 strings of '123'
-
- Is there some way using a form of grep to do this? Egrep has '()' grouping
- but doesn't have the \{n,m\} stuff. And grep has the opposite. Grrr.
-
- Secondly, what if my file looked like:
-
- 123.105.113.13
- 123.123.113.13
- 123.123.123.13
- 123.123.123.123
-
- How would I print out the lines matching the following conditions:
- 1) only one occurence of '123'
- 2) two or more occurences of '123'
- 3) at least two but no more than 4 occurences of '123'.
-
-
- Is grep disabled or am I?
- If it turns out that the grep family is disabled, I would like to here
- some suggestions with sed, awk, or perl which might do the trick.
-
-
- -tms
-
-
- ~
- ~
- --
- >From the Lab of the MaD ScIenTiST:
-
- navarra@casbah.acns.nwu.edu
-
-
-