I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a third command, 'cut':
tail -f logfile | grep org.springframework | cut -c 25-
The cut command would remove the first 25 characters of each line for me if it could get the input from grep! (It works as expected if I eliminate 'grep' from the chain.)
I'm using cygwin with bash.
Actual results: When I add the second pipe to connect to the 'cut' command, the result is that it hangs, as if it's waiting for input (in case you were wondering).
What you have should work fine -- that's the whole idea of pipelines. The only problem I see is that, in the version of
cut
I have (GNU coreutiles 6.10), you should use the syntaxcut -c 25-
(i.e. use a minus sign instead of a plus sign) to remove the first 24 characters.You're also searching for different patterns in your two examples, in case that's relevant.
Assuming GNU grep, add
--line-buffered
to your command line, eg.Edit:
I see grep buffering isn't the only problem here, as cut doesn't allow linewise buffering.
you might want to try replacing it with something you can control, such as sed:
or awk
On my system, about 8K was buffered before I got any output. This sequence worked to follow the file immediately: