OK, sorry for that sed line, it is obviously difficult to read but that
is the way sed is.
when you use \( \) constructs, you store the part that is matched between
the "()" under a number (sequentialy affected. so to retreive the result
you use \1 for the first one , \2 for the second one ...
for ths to work, you have to mach the entire line from the 1st char to
the last.
so my script substitute the entire line by what was stored under \2
the line is decomposed by matching :
from the begining every char until "driver" followed by some spaces (and
storing the words before driver under \1 but this will not be used ...)
then store under \2 the next word (limited by a space [should be modified
to allow tabs, comma ...] as a word separator).
then store the end under \3 (don't know why i stored everything but i did
it).
yes, sed is far worst than awk and perl ... but i though this would be
easier to do with sed, maybe i was wrong.
pascal
-----Original Message-----
From: omer ansari [SMTP:[EMAIL PROTECTED]]
Sent: Friday, April 23, 1999 2:12 PM
To: LENGARD Pascal OCISI
Subject: Re: grep for line.
> with the same example something like this output only the word after
> "driver":
> cat example | sed -e 's/\(.*\)driver *\([^ ]*\) \(.*\)/\2/'
>
> will output:
> can
> is
>
hi i've been wracking my brain on that sed line u wrote for quite some
time,
i even went to the man pages on the net (as i dont have access to a linux
box right now). but i couldn't really understand how that line does what
it
does.
could u fill in the gaps?
i understand that u are substituting X instead of Y. Now originally, Y
stands for: \(.*\)driver *\([^ ]*\) \(.*\)
and X stands for: 2
Y is decrypted as: anything and everything before the word driver and
anything after it? and thats where i get lost!
could u just take a little time out and explain this to me?
regards,
>
> 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]
> ----------------------------------------------------------------
>
>