0

I have a log file which gets new entries continuously. How can I keep grep running and print only the new matching lines(the old ones only once) which are added to the file to the shell? Is there a way to use the command without having to write a script file? Sed would be also possible.

grep [any options to keep it running?] 'word' filename
MWO
  • 2,627
  • 2
  • 10
  • 25
  • @paulsm4 it is very nice but it only answers my question partly, because they use tail which only prints the latest lines plus the continuous stream. But it does not print the whole file plus continuous stream. When I use it with cat file | grep --line-buffered my_pattern it prints the old lines but not the stream, it stops with "Binary file (standard input) matches" – MWO Nov 05 '20 at 22:44
  • @perreal I mean the new lines which are added to the file. I used the word "stream" because they use it in the referenced question. – MWO Nov 05 '20 at 23:05
  • 1
    `tail` is the correct tool for this, like so: `tail -f -n +1 filename | grep 'word'`. – perreal Nov 05 '20 at 23:11
  • https://stackoverflow.com/a/23512981/390913 – perreal Nov 05 '20 at 23:34
  • @perreal this works thanks you very much! – MWO Nov 06 '20 at 16:40

0 Answers0