[aclug-L] Re: a dump grep question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Maverick wrote:
>
> Hi, all
> I have file testfile, and I want to get the exactly
> occurance on the same line.
> //testfile
> 111 ABC DEF IJK PPP
> 111 XTS XXX XXX XXX
> 222 MNO PRQ STU PPP
> 333 ... ... ... 111
> 444 ... ... ... PPP
>
> I only interest in grep the line contain
> 111 and PPP.
> I don't know it is possible using grep or egrep to do
> it?
grep '111.*PPP'
Where '.*' matches any number of any intervening characters.
Grep and egrep are the same in this case.
> #grep -w "111" & "PPP" testfile <-- error
The & is a magic shell character. It says: run the command in
the background. In this case, grep is waiting to read stdin.
The error message is from the shell, which cannot find PPP
to run.
> 111 ABC DEF IJK PPP <--- I want this output
>
> I know that egrep support "|" (boolean or) to grep,
> but I don't know it support "&"(boolean and). Please
> help.
Grep/egrep support regular expressions, which are ways of specifying
pattern matches. Not the same as boolean logic. In egrep, | means
alternation: either the previous regular expression or the following
regular expression (often, but not necessarily, parenthesized). If
you don't use | between two regular expressions, you mean to find
the first regular expression immediately followed by the next
regular expression. Each character you search for is a regular
expression, so:
grep xyz
searches for RE 'x' immediately followed by RE 'y' immediately
followed by RE 'z'.
To experiment, you might try doing something like:
ls | egrep ...
and vary the egrep expression to see what gets selected. Work your
way through the man page.
> Regards,
> Mav
>
> I don't know I can do
--
/*
* Tom Hull * thull at kscable.com * http://www.ocston.org/~thull/
*/
-- This is the discussion@xxxxxxxxx list. To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
|
|