Reputation: 1420
abc def
ijk lmn
opq rst
uvw xyz
sed '/\(.*\)def/{N;s/\(.*\)def\n\(.*\)lmn/Replaced\nSuccess/}' file
Replaced
Success
opq rst
uvw xyz
Works as expected.
2013-09-17-01:02:43 User: [email protected]
2013-09-17-01:02:43 Last login time: Never
hello
how are you
catch up tmrw
sed '/\(.*\)tld/{N;s/\(.*\)tld\n\(.*\)Never/Replaced\nSuccess/}' file
This doesn't work.
Replaced
Success
hello
how are you
catch up tmrw
Where is the issue?
Upvotes: 1
Views: 697
Reputation: 75478
Make sure your file ends with LF and and not CRLF. Try to run it with dos2unix before running it with sed.
dos2unix file
Or completely strip off its trailing spaces (includes \r
)
sed -i 's/[[:space:]]*$//' file
Upvotes: 1
Reputation: 11469
The way you have written does work. To make it more readable, this works too.
sed '/.*tld/{N;s/.*tld\n.*Never/Replaced\nSuccess/}' file
Upvotes: 1