Quote:
Originally Posted by tinkulim
is there a way to number the matched pattern using sed?
|
If you want the line number the hit occurs on and the line itself, then this should work:
Code:
sed -n '/foo/{=;p}' infile
if you need to show the number of hits and the line itself you need to use something else then sed. Here's an awk solution:
Code:
awk 'BEGIN{ cntr = 1 } /foo/ { print cntr, $0 ; cntr++ }' infile