Reputation: 55769
I want to tail a log, pipe it through grep to find the log entries I am interested in. This is straightforward:
tail -f logfile | grep foo
But how can I ensure only selected parts of each line are output? Ideally those parts matching a regex.
Upvotes: 1
Views: 70
Reputation: 114478
You would use grep -o foo
or grep --only-matching foo
, where you would expand foo
to include the entire part of the line that you wanted. The official GNU grep
manual on this option is here.
Upvotes: 1