0

Example:

a43
test1
abc
cvb
bnm
test2
kfo
a43
test1
abc
cvb
bnm
test2
kfo
a43
test1
abc
cvb
bnm
test2
kfo

i need to find all lines between first occurence of test1 and test2. Below grep command does not work for this :

grep -A100000 test1 file.txt | grep -B100000 test2 > new.txt

can you please let me know if any modifications are needed to do the same?

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
new_user
  • 1
  • 1
  • This question (and discussion) are likely helpful here: https://stackoverflow.com/questions/23934486/is-a-start-end-range-expression-ever-useful-in-awk – Etan Reisner Jun 23 '15 at 17:35

1 Answers1

0

This awk should do the job:

awk '/test1/{p=1} p; /test2/{exit}' file
test1
abc
cvb
bnm
test2
anubhava
  • 761,203
  • 64
  • 569
  • 643