Reputation: 67
This currently works ok, want to add the following capabilities: pipe search items from mygrepitemslist.txt (line by line) instead of my explicitly stating error1 and error2 (bonus if spaces can be include in search)
in other words want something read file mygrepitemslist.txt and pipe to grep in this code example
instead of in the code below: grep "error1\|error2"
mygrepitemslist.txt has: error1 errors error3 with space error4 with multiple spaces
Would like to use what I have mainly because I use it for other things and it's familiar, just stuck on how to feed it grep strings from a file then outputting the match with filename
tail -Fn0 /var/log/*.log | \
while read line ; do
echo "$line" | \
grep "error1\|error2" #pipe mygrepitemslist.txt linebyline here?
if [ $? = 0 ]
then
echo "$line" #how to show error + filename here?
fi
done
The overall results is:
want to tail/follow multiple files
search for strings read from file called mygrepitemslist.txteach line is search term
output is: error search with matching file name
Upvotes: 1
Views: 260
Reputation: 731
you can use -f
option for specifying file with patterns
tail -Fn0 /var/log/*.log | grep -of mygrepitemslist.txt
Upvotes: 1