Reputation: 13
I would like to print the content of a file starting a particular line number till the first occurrence of a pattern and immediately stop the search & print. I tried this one:
sed -n '2,/{p; :loop n; p; /pattern/q; b loop}'
but without success. How can this be achieved? Thanks for your help.
Upvotes: 1
Views: 194
Reputation: 88899
With GNU sed: to stop after a line containg pattern:
sed -n '2,/pattern/{p;/pattern/q;} file
Upvotes: 0
Reputation: 786011
You can use sed
:
sed -n '2,/pattern/p' file
Or this awk command:
awk 'NR==2{p=1} p; /pattern/{exit}' file
Upvotes: 1