Multiline cropping

I have an html file that I want to crop. I want to delete a section from the very beginning up to the given line and from another line to the end. How to do this, preferably with sed?

+3
source share
2 answers

With GNU sed:

sed '/mark1/,/mark2/d;/mark3/,$d'

this

abc
def
mark1
ghi
jkl
mno
mark2
pqr
stu
mark3
vwx
yz

becomes

abc
def
pqr
stu
+6
source

you can use awk

$ cat file
mark1 dsf
abc
def
before  mark2 after
blah mark1
ghi
jkl
mno
wirds mark2 here
pqr
stu
mark3
vwx
yz

$ awk -vRS="mark2" '/mark1/{gsub("mark1.*","")}/mark3/{ gsub("mark3.*","");print;f=1 } !f ' file

 after
blah
 here
pqr
stu
0
source

Source: https://habr.com/ru/post/1740693/


All Articles