[PLUG] grep question
Jeme A Brelin
jeme at brelin.net
Sat Aug 2 21:14:02 UTC 2003
On Sat, 2 Aug 2003, Steven Raymond wrote:
> How do I make grep output all lines of a file, after the first ocurrance
> of a given text?
>
> Say I have a log file that starts on July 1 and ends on August 5. I
> simply want to output the file, but beginning on July 15, for example.
>
> Anyone familiar with Cisco "show run | begin ethernet0" will know what I
> mean.
Well, I can't think of a SIMPLE way to do it.
[Assuming gnu grep, now]
grep -A 99999999 regexp file
That will output 99999999 lines after and including the matched lines.
Kludgey, but I can't figure out how to say "everything".
It's either that or something UGLY like this:
FIRST_MATCH=`grep -n regexp file |head -1 |sed -e 's/\([0-9]*\):.*/\1/'`
tail -$[`wc -l file|sed -e 's/^ *\([0-9]*\) .*/\1/'` - $FIRST_MATCH +1] file
How do you like THAT shit?
Of course, I'd probably use perl.
J.
--
-----------------
Jeme A Brelin
jeme at brelin.net
-----------------
[cc] counter-copyright
http://www.openlaw.org
More information about the PLUG
mailing list