Score:0

Linux cli pipeline command tail and grep

eg flag
olo

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

Michael Hampton avatar
cz flag
It seems fine. What exactly do you mean by "not working"?
Score:1
mx flag

You can do it with awk alone:

tail -f somefile.log | awk '/keyword/ {print $4}'
eg flag
olo
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?
digijay avatar
mx flag
You can combine as many pipes as you want/need in one line. What exactly is not working for you?
eg flag
olo
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)`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.