LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Using cut in continuous follow (tail -F) (https://www.linuxquestions.org/questions/linux-newbie-8/using-cut-in-continuous-follow-tail-f-4175616461/)

Sefyir 10-26-2017 07:37 PM

Using cut in continuous follow (tail -F)
 
I want to follow a file, filter for the word FOOBAR and only display certain fields of it by delimiting with a space.
Is this possible?

This works ok, but I just want the 1st, 2nd and 5th field
Code:

sudo tail -F /var/log/syslog | grep --color FOOBAR
This just sits there with no output.
Code:

sudo tail -F /var/log/syslog | grep --color FOOBAR | cut -d' ' -f 1,2,5
Running this works as expected (example output would be Oct 2 127.0.0.1)
Code:

sudo tail /var/log/syslog | grep --color FOOBAR | cut -d' ' -f 1,2,5

norobro 10-26-2017 08:18 PM

Try using the "--line-buffered" option of grep: https://www.gnu.org/software/grep/ma...#Other-Options

Sefyir 10-26-2017 11:01 PM

That solved it. Thanks

Code:

      --line-buffered
              Use line buffering on output.  This can cause a performance penalty.

Code:

sudo tail -f /var/log/syslog | grep --line-buffered --color FOOBAR | cut -d' ' -f 1,2,3,7,11


All times are GMT -5. The time now is 12:07 AM.