Monday 15 April 2013

grep - Bash processing last line in file only -


I am trying to process the last line in the saved file every time. This is what I have done so far:

  tail- F -n0 '/path/to/foo.txt' | Grep "." | While reading the line, echo "$ line"   

If I leave grep, I will get the previous row, the script runs for the first time, but when the target file is saved For this, the entire file will be output, not just the new last line (desired behavior).

I need grep to return the strip, because it is the last character in these text files, I find the above paped output with pipes in grep, do not return anything.

I am a newbie here, so any guidance is highly appreciated.

I'm afraid that tail does not work like this After processing the initial query -n0 , the -f / -F stream all the data, and as far as I know, there is no way To obtain the last line of new data using a single tail orientation.

The solution that can be made every time you change the file to tail on Linux, you can use the inotify subsystem for efficiency, not me The general idea will look like what Macoose equivalent is:

  while initifywait -e modify / your / file # This will wait for the next change on Linux tail-1. One ?? | Your processing here ?? | Done    

No comments:

Post a Comment