Complete.Org: Mailing Lists: Archives: discussion: March 2001:
[aclug-L] Re: a dump grep question
Home

[aclug-L] Re: a dump grep question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: a dump grep question
From: Tom Hull <thull@xxxxxxxxxxx>
Date: Mon, 26 Mar 2001 14:07:34 -0600
Reply-to: discussion@xxxxxxxxx

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


[Prev in Thread] Current Thread [Next in Thread]