Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tail multiple files and grep the output [closed]

Tags:

grep

unix

tail

I would like to grep a pattern from multiple log files which are being constantly updated by some processes and tail the output of this grep continuosly. Below command doesnt work and I get

  • tail: warning: following standard input indefinitely is ineffective
tail -f  | grep --line-buffered "Search this: " /var/links/proc2/id/myprocess*/Daily/myprocess*.log

Can someone help sort this out?

like image 312
212 Avatar asked Sep 30 '13 08:09

212


2 Answers

You should have a look at multitail tool (Install using sudo apt-get install multitail)

In short, with multitail, you need to use the --mergeall flag for viewing output of all in one place

multitail --mergeall /var/links/proc2/id/myprocess*/Daily/myprocess*.log  | grep --line-buffered "Search this: " 

You can do the same without using grep

multitail -E "Search this: " --mergeall /var/links/proc2/id/myprocess*/Daily/myprocess*.log  

To view the output individually using multitail, this will give the filename as well.

multitail -E "Search this: " /var/links/proc2/id/myprocess*/Daily/myprocess*.log 
like image 53
Anshul Goyal Avatar answered Sep 21 '22 08:09

Anshul Goyal


the mistake is that you give the files to the grep command and not the tail.

the tail -f needs to get the files as input. try:

tail -f  /var/links/proc2/id/myprocess*/Daily/myprocess*.log | grep --line-buffered "Search this: "

to get also the file names (however it will not be like grep output it is):

tail /var/links/proc2/id/myprocess*/Daily/myprocess*.log | grep --line-buffered -e'^==> .* <==$' -e'Search this: '
like image 36
Udy Avatar answered Sep 24 '22 08:09

Udy