The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 06-04-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
You don't need a while loop: "tail -f" is already an infinite loop until you manually terminate the process.

If you try:
Code:
tail -f file.log | grep "something" > output.txt
Your output file will remain empty until the grep buffer is flushed, which happens every "tot" bytes. If your grep version supports the option "--line-buffered" use it and you're done, otherwise you may need a while loop like:

Code:
tail -f file.log | while read LINE
do
   echo "$LINE" | grep "something" >> output.txt
done
Hope this helps.