Count lines before a match (and after)

Lines before a match:

sed -n '0,/pattern/p' file | wc -l

 

Lines after a match:

sed -n '/pattern/,$p' file | wc -l
Advertisements