home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
- From: navarra@casbah.acns.nwu.edu (John Navarra)
- Subject: Argh! Regular expressions with [ef]grep
- Message-ID: <1992Jul25.035016.17217@news.acns.nwu.edu>
- Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
- Organization: Northwestern University, Evanston Illinois.
- Date: Sat, 25 Jul 1992 03:50:16 GMT
- Lines: 70
-
- 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?
-
- -tms
-
-
- ~
- ~
- --
- From the Lab of the MaD ScIenTiST:
-
- navarra@casbah.acns.nwu.edu
-