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!

tail and grep together

Status
Not open for further replies.

peterneve

Programmer
Jan 24, 2002
50
GB
I need to write a simple script that reads a continuous live log file, and if I find a particular string, write the next line to another log file. I've tried vaiour tail -f | grep combinations. This should be simple, but I can't get it so work. Any ideas?
 
tail -f seems to be a good starting point.
What have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
tail -f largelogfile | grep something >> newlogfile

doesn't seem to produce anything in newlogfile. Even this would be a start.
 
I have also tried

Code:
tail -f largefile | awk '/something/{getline;print}' >> 
newfile

which produces nothing, although it works without the -f.

Thanks,
 
Try without output redirection >> newlogfile
I guess this will work.
It seems to be a problem of output buffering.
 
by the way, may I ask if there are situations where you really need both -f and redirection?
If you want to see it in real time, leave away redirection.
If you need it afterwards, do a grep afterwards, leave away tail.
 
Yes, I have had similar problems with tail -f into an awk script, it seems to be buffering either the output from tail or the input to awk.

I had to replace my awk script with a perl script, and used the code described in the open section on the perlfunc man page to make STDOUT unbuffered.

I don't know why making STDOUT unbuffered fixed the problem (I would have thought it should be STDIN), but it did.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top