0

I have been trying to follow and filter an log file using

less +F +G /var/log/messages |  grep -v -f ignoredwords.txt | grep -f words.txt

but it seems the file is not continoulsy read and the operation stops once the whole file is read

i have tried using same with tail -f but that seems to be skipping alot of lines any suggestion to improve

xhienne
  • 5,738
  • 1
  • 15
  • 34
Saadi381
  • 55
  • 1
  • 2
  • 9
  • depending on your version, you could use `grep --line-buffered` or install and use `stdbuf -o0 grep ...` – Sundeep Jul 31 '18 at 03:41
  • `less` is wrong here, you want simply `tail -0f` (perhaps with some additional options). – tripleee Jul 31 '18 at 03:49
  • this doesnot seem to be a problem which duplicate grep , even using single grep and less terminates once the whole file is read (does not keep following the file) – Saadi381 Jul 31 '18 at 03:49
  • i have been using tail , but that seems to be missing few lines or may be i am performing too much for grep , i have like 30 words in match and about 40 in ignore words list...any suggestions – Saadi381 Jul 31 '18 at 03:51
  • Yes, exactly. The pipe causes buffering. This is a common FAQ. Maybe replace the two `grep`s with a single Awk script, somewhat also depending on the sizes of the word lists. – tripleee Jul 31 '18 at 03:52
  • struggling with awk , as it couldnt use the words from file to search for.. – Saadi381 Aug 01 '18 at 03:06
  • awk certainly can use words from a file. It's a programming language, you can write any program in it you want, including a program that reads the first file it's given into a map and checks lines in the second file against that map. – Charles Duffy Feb 22 '21 at 19:11

0 Answers0