write to a file after piping output from tail -f through to grep

12,592

Solution 1

Maybe you have an issue with buffering? See BashFAQ: What is buffering?

You could e.g. try:

tail -f /var/lof/freeswitch/freeswitch.log | grep --line-buffered "Playing:" > temp

Solution 2

-f, --follow[={name|descriptor}]
              output appended data as the file grows;

It scans the file as it grows. And it is a process with an interval. You can only interrupt it.

Use parameter:

-c, --bytes=K
              output the last K bytes; alternatively, use -c +K to output bytes starting with the Kth of each file  

or

-n, --lines=K
              output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth

EDIT: as bmk said:

grep --line-buffered  

think it will help you

Solution 3

Did you put the file name after the >?

tail -f /var/lof/freeswitch/freeswitch.log | grep "Playing:" > temp
Share:
12,592
Reddy
Author by

Reddy

I am student in UMKC currently pursuing masters' in computers....interested in XML data management, Algorithms...

Updated on June 19, 2022

Comments

  • Reddy
    Reddy almost 2 years

    I'm looking to write to a file after piping output from tail -f through to grep. Say,write to a file "temp" for all lines with "Playing:" within in error_log "FreeSwitch.log".

     tail -f "/var/lof/freeswitch/freeswitch.log" | grep "Playing:" > temp
    

    but not working ! It is a centos 5.5