1

I wanted to grep some logs, while tailing them, and print only a part of each line, since the lines are too long.

I can't figure out why the combination I use doesn't work; the procedure follows:

echo 'Jun 29 16:27:00 someip rails[pid]: Killed a transaction
Jun 29 16:28:00 someip rails[pid]: Killed a transaction' > /tmp/test

# Shows the lines
tail -f /tmp/test | grep Killed

# Shows the lines
grep Killed /tmp/test | cut -c -43

# Shows the lines
cat /tmp/test | grep Killed | cut -c -43

# Doesn't show them
tail -f /tmp/test | grep Killed | cut -c -43

Why doesn't the last combination work?

3

1 Answer 1

0

As noted in the comments , the issue is due to buffering. What you can do is to run command with stdbuf as shown here.

stdbuf -i0 -o0 -e0 tail -f /tmp/test | grep Killed | cut -c -43

On side note, you probably could get rid of grep and cut pipeline, and use :

stdbuf -i0 -o0 -e0 tail -f /tmp/test | awk '/Killed/{print substr($0,length($0)-43)}'

Not the answer you're looking for? Browse other questions tagged .