with the same example something like this output only the word after   
"driver":
cat example | sed -e 's/\(.*\)driver *\([^ ]*\) \(.*\)/\2/'

will output:
can
is


hope this helps
pascal

 -----Original Message-----
From: Ray Olszewski [SMTP:[EMAIL PROTECTED]]
Sent: Friday, April 23, 1999 12:44 AM
To: [EMAIL PROTECTED]
Subject: Re: grep for line.

While I don't know the answer (I stopped using awk years ago), I may
understand the question a bit better. As I read the original poster's
messages, he wants to do the following:

1. Find one or more lines in a file (or set of files) that contains a
specific string. This, as we've all been noting, is a conventional   
problem
for grep.

2. Examine the output of grep to find a string that is in an   
*unpredictable*
location in each of the lines.

awk can probably do the second, and I'm sure someone on the list can   
explain
how (not me; I use perl for this sort of thing), but Richard's answer   
relies
on the target string being in a known position. To extend his examp,e   
it's
as though you needed to find the word following SSC/ESCC in the following   
2
lines:

The SCC/ESCC driver can support any mix of SCC and ESCC chips
The revised SCC/ESCC driver is also able to support any mix of SCC and   
ESCC
chips

Or imagine a set of lines all about the same topoc, each with a number in   
an
unknown location. How would one find all the numbers?

One or the other of these is, I think, roughly what the poster wants  to
achieve.

At 09:52 PM 4/22/99 +0000, Richard Adams wrote:
>According to omer ansari: While burning my CPU.
>>
>> awk might suit ur needs.
>
>It certanly might, however we still dont realy know what the origanal   
poster
>wants to do, he talks about "regexp" but would not "grep -e" expression"   
do
>the same, or there abouts.??
>
>Something like the following.
>An example, the following line in a file;
>The SCC/ESCC driver can support any mix of SCC and ESCC chips
>
>Now suppose we only want to get the word after SCC/ESCC, we would use;
>
>grep -e "SCC/ESCC" filename  | awk '{print $3}'
>
>That will produce the word "driver" for each and every match because its   
the
>3rd word in the line matched by grep -e, -e = expression enclosed in "   
".

 ------------------------------------"Never tell me the odds!"---
Ray Olszewski                                        -- Han Solo
762 Garland Drive
Palo Alto, CA  94303-3603
650.328.4219 voice                [EMAIL PROTECTED]
 ----------------------------------------------------------------

Reply via email to