0

I am using tail and grep to find something like 'Apple' on multiple files i need to get the file name that found the result in

tail -F files_name grep --line-buffered -e 'Apple' -e 'Orange' while read ;  do    while :;    do     echo -en "\007";     sleep 1;  done  ; done

2 Answers2

1

Look to me like you overthinked.

grep 'Apple\|Orange' file1 file2

Searches for the string Apple or Orange in both file1 and file2. grep will output the filename with : as separator. You can use grep -l 'Apple\|Orange' file1 file2 to print filenames only.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • i cant use grep -l in the tail this will not bring the file name "grep: No such file or directory" and this what happen when i use grep without -e – aisr alqudah Jan 24 '19 at 04:35
  • How do you use grep "in the tail"? You mean you want to _follow_ files (`tail -f`) and simultaneously `grep` for results? – KamilCuk Jan 24 '19 at 06:25
  • The above code read the files continuously and when the grep get data it keep beeping .. i am reading from multiple file at the same time i need to get the name of file that the result appear in – aisr alqudah Jan 24 '19 at 14:24
1
tail -f *txt | awk '/^==> / {a=substr($0, 5, length-8); next} {print a":"$0}' | grep -ni "Apple\|Orange"
Arnaud F.
  • 8,252
  • 11
  • 53
  • 102
Rakesh
  • 11
  • 2