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
  • 25,268
  • 11
  • 79
  • 127
pedr0
  • 2,941
  • 6
  • 32
  • 46

3 Answers3

1

You can do it with sed:

sed -n '/my begin line/,/my end line/p'
Barmar
  • 741,623
  • 53
  • 500
  • 612
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
  • 189,393
  • 32
  • 233
  • 301
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
  • 266,786
  • 75
  • 396
  • 414