linux - grep -A <num> untill a string -
assuming have file containing following:
chapter 1 blah blah blah num blah num num blah num blah ... blah num chapter 2 blah blah and want grep file take lines chapter 1 blah blah blah num (the line before next chapter).
the things know are
- the stating string
chapter 1 blah blah - somewhere after there line starting
chapter
a dummy way
grep -a <num> -i "chapter 1" <file> with large enough <num> whole chapter in it.
any ideas?
this easy awk
awk '/chapter/ {f=0} /chapter 1/ {f=1} f' file chapter 1 blah blah blah num blah num num blah num blah ... blah num it print line if flag f true.
chapter 1 , next chapter changes flag.
you can use range awk less flexible if have other stuff test.
awk '/chapter 1/,/chapter [^1]/ {if (!/chapter [^1]/) print}' file chapter 1 blah blah blah num blah num num blah num blah ... blah num
Comments
Post a Comment