Sample Header Ad - 728x90

How can I use sed to replace a multi-line string?

462 votes
18 answers
643477 views
I've noticed that, if I add \n to a pattern for substituting using sed, it does not match. Example: $ cat > alpha.txt This is a test Please do not be alarmed $ sed -i'.original' 's/a test\nPlease do not/not a test\nBe/' alpha.txt $ diff alpha.txt{,.original} $ # No differences printed out How can I get this to work?
Asked by Belmin Fernandez (9877 rep)
Dec 7, 2011, 06:03 PM
Last activity: Dec 24, 2024, 02:10 PM