0

I would like match a text like that

my  begin line
not useful text that I cannot match because I don't know how it is composed
my end line

I'd match all the text above, my problem right now is that I cannot match all the text but just the first line with a regext like that:

my begin line\n.*my end line

So I am confused, any help ?

m0skit0
  • 23,973
  • 11
  • 79
  • 120
pedr0
  • 2,802
  • 5
  • 30
  • 44

3 Answers3

1

You can do it with sed:

sed -n '/my begin line/,/my end line/p'
Barmar
  • 669,327
  • 51
  • 454
  • 560
1

you mentioned awk in comments:

this gives you all text, (including lines with begin, end pattern)

awk '/my  begin line/,/my end line/' file

this gives you only lines between the begin/end patterns (without lines with begin, end pattern)

awk '/my  begin line/{f=1;next;}/my end line/{f=0}f' file
Kent
  • 181,427
  • 30
  • 222
  • 283
1

To print the lines between two patterns, excluding the lines containing the patterns themselves use:

sed -n '/my begin line/,/my end line/ {/my begin line/n;/my end line/!p}' file
dogbane
  • 254,755
  • 72
  • 386
  • 405