Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying part of the text -sed?

Status
Not open for further replies.

kimmers

Technical User
Aug 1, 2002
24
FI
Good Day,

I would like to put a "query" script to a logfile from cron which is run scheduled on a certain day.
lets's say we have a logfile containing some data from Feb 21st to Feb 24th and I want to run a script that copies the content from Feb22 to Feb 24 into a new file

cat logfile

Feb 21
nmxcvc
Feb 22
jvjhkcvlv
kljjksdjl
Feb 23
kkfgooo
jjfgjhkgc
Feb 24
jsdjfjsdf

so the desired output would look like this
Feb 22
jvjhkcvlv
kljjksdjl
Feb 23
kkfgooo
jjfgjhkgc
Feb 24
jsdjfjsdf

I can do this manually using vi but putting this into a script is more complicated.
There was an example of a mygrep (sed -n -e &quot;/$1/p&quot; <$2)
where you give the command i.e mygrep &quot;Feb 22&quot; logfile
where it searches the pattern from the logfile but I would like to extend this
from that date to the end of that file and direct the output into a newfile.

Any help on this?

#Kimmers
 
Hi,

You can do:

awk '/Feb 22/,/EEEE/' logfile > otherfile

This will print all from the line with &quot;Feb 22&quot; till the end.
&quot;EEEE&quot; can be any non existing string ... &quot;Long live king Moshiach !&quot;
 
Thanks Bro,

That helped.
So EEEE here is kind of EoF (End of File).

Reg,

#Kimmers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top