Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, let me start with the overall outcome that i want to achieve.

There is just one log, which will have info on certain devices, that i am upgrading.

I use "tailf log" to monitor the log.

Now, say, I am upgrading 10 devices, the log will go on populating lines pertaining to ips of each 10 devices.

I am not concerned about all lines of the logs, but very few lines, like, image being copied to device, image deleted, image uploaded, device reload issued and so on..

what i am looking for is.. a script which will parse the ongoing logs, and grep for the txts that i am concerned about, like "image deleted", "device reload issued" and go on populating these grepped outputs to files named image_deletion_messages, device_reload_messages and so on..

and again, parse these files (image_deletion_messages, device_reload_messages) to determine ips from the logged messages and then save those ips to files named image_deleted_devices, reload_devices...........

And in turn, i'll monitor these files (image_deleted_devices, reload_devices) using tailf, instead of monitoring the entire log.

tailf log |grep "image deleted" >> image_deletion_messages

tailf image_deletion_messages |grep (a list of ips) >> image_deleted_devices

And the same way for other messages............

Above set of commands as part of a script..

and finally, i'll just monitor the below files alone..

tailf image_deleted_devices

and so on......

I tried the above way and it doesn't seem to work. Maybe i am doing it wrong. Please advise.

share|improve this question

Something like this...

E.g., pipegrep:


tail -f "$2" | while read log
    echo $log | grep "$1"

This is obviously very basic. Enhance as needed.

share|improve this answer
Is this do the same ? tail -f "$2"|grep "$1" ? – X Tian Feb 11 '14 at 23:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.