0

I am using tail to monitor a log file and using grep to filer the keyword.

tail -F somefile.log | grep "keyword" is working tail -F somefile.log | awk '{print $4}' is working

but if to put them together is not working, like tail -F somefile.log | grep "keyword" | awk '{print $4}'

Is this the wrong way to use |? How to make tail -F somefile.log | grep "keyword" | awk '{print $4}' to work? Thanks

if I want to run a command after awk like tail -F somefile.log | grep "keyword" | awk '{print $4}' | ./abashfile.sh how to achieve something like this, looks like multiple | is not quite right for combining everything in 1 line. Thanks

olo
  • 103
  • 3

1 Answers1

1

You can do it with awk alone:

tail -f somefile.log | awk '/keyword/ {print $4}'
digijay
  • 1,155
  • 3
  • 11
  • 22
  • Thanks for the answer, I am trying to figure out multiple `|`. eg I want to run a command after print `tail -f somefile.log | awk '/keyword/ {print $4}' | echo "received" >> file` looks the extra `|` is not something to be used? – olo Aug 21 '21 at 09:36
  • 1
    You can combine as many pipes as you want/need in one line. What exactly is not working for you? – digijay Aug 21 '21 at 10:00
  • Thanks! I wanted to do something like `tail -f somefile.log | awk '/keyword/ {print $4}' | echo {print $4}(get the result) >> filename (to another file)` – olo Aug 21 '21 at 10:34