I'd like to tail a file but only output lines that have a certain string in them. Is this possible?
|
feedback
|
|
use grep. Its built just for that purpose. To find lines from a tail of /var/log/syslog that have "cron" in them, just run:
And since it accepts anything over stdin, you can use it on the output of any other command as well, by piping in the same way as above (using the | symbol). | |||||||
feedback
|
|
Here's a couple other ideas, which while not as simple, may offer some interesting additional flexibility: First, you can filter with awk instead of grep:
that works exactly the same as the example using
which will print the 6th through the last field of the output (fields are whitespace separated) Another similar idea is to use a perl one-liner:
that works exactly like
Obviously all of these sorts of things can be done with other tools too, but I wanted to illustrate that there are some fun ways to use more general purpose languages like awk or perl here. | |||
|
feedback
|
|
Another trick worth noting, if you have a CSV file with headers that you want to omit, e.g.:
It doesn't matter how long the input to | |||
|
feedback
|