I simply want to do following
replace
EXTRATHING {
};
by
SOMETHING {};
in inputfile. For this, I tried
sed -e 's/EXTRATHING {\n};/SOMETHING/' input_file.txt >outfile.txt
This doesn't work. Can someone suggest what would be the correct way of doing this with sed?
sed -n '1h;1!H;${;g;s/EXTRATHING {\n};/SOMETHING {};/g;p;}' input_file.txt
would do it.
The problem with this is that it stores the whole input string in sed's buffer.
See sed and Multi-Line Search and Replace for more info, and a more efficient version.
sed -i.bak '/EXTRATHING/{N;s//SOMETHING/;s/\n//}' input_file.txt
sed -e '/begin/,/end/{s/begin/replacement/p;d}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With