[ACCEPTED]-How do you pipe input through grep to another utility?-cut

Accepted answer
Score: 30

Assuming GNU grep, add --line-buffered to your command 5 line, eg.

tail -f logfile | grep --line-buffered org.springframework | cut -c 25-


I see grep buffering isn't the 4 only problem here, as cut doesn't allow 3 linewise buffering.

you might want to try 2 replacing it with something you can control, such 1 as sed:

tail -f logfile | sed -u -n -e '/org\.springframework/ s/\(.\{0,25\}\).*$/\1/p'

or awk

tail -f logfile | awk '/org\.springframework/ {print substr($0, 0, 25);fflush("")}'
Score: 12

On my system, about 8K was buffered before 2 I got any output. This sequence worked to 1 follow the file immediately:

tail -f logfile | while read line ; do echo "$line"| grep 'org.springframework'|cut -c 25- ; done

More Related questions