Warm tip: This article is reproduced from stackoverflow.com, please click
linux sed

linux sed remove block of code with linebreak

发布于 2020-04-04 10:09:58

Trying to remove this entire block of code from a script:

https://pastebin.com/gBnFBQSR

I am able to do so up until the linebreak and ending }

sed '/var gfjfgjk/,/appendChild(s);\n}/d'

how can I have it include the linebreak and } at the end

Questioner
JCats
Viewed
52
JCats 2020-02-01 00:24

Thanks to @Wiktor Stribiżew link:

for i in $(grep -rl gfjfgjk) ; do if grep -m1 gfjfgjk $i >/dev/null 2>&1 ; then echo $i ; sed -i -e '1,6d;7s/^}//' $i ; fi; done

The only different really is, I wanted to make sure gfjfgjk matched the first line of the file in case it was injected somewhere else in the script and then sed removed the first 7 lines of legit code.