Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed or awk to print lines between words

Tags:

sed

how to print all lines between "section B (" To the next "section" word that begin in line?

section A (

. .

)

section B (

. .

)

section C (

. .

)

like image 987
lidia Avatar asked Dec 12 '22 20:12

lidia


1 Answers

sed -n '
  /^section B/!n;
  /^section B/d;
  /^)/q;
  p
' yourfile

Explanation of the above sed script, in steps:

  1. While the line does not ! start with section B move to the next line.
  2. After the we reached the desired line remove the section B text line.
  3. In case the line starts with ) we quit.
  4. Else we print the currently processed line.
like image 119
mhitza Avatar answered Jan 21 '23 14:01

mhitza