Let say pattern is string "Love"
input
This is some text
Love this or that
He is running like a rabbit
output
This is some text
Love this or thatHe is running like a rabbit
I've noticed that sed is very unpleasant for deleting newline characters, any idea?
\n is a way of representing a newline character in various languages and programs but as the name suggests, a newline is only stored in a file as a single character.
The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
You can use this:
sed '/^Love/{N;s/\n//;}' love.txt
details:
/^Love/
identifies the line to treat, if you like you can use /[Ll]ove/
instead
N
adds the next line to the pattern space. After this command the pattern space contains Love this or that\nHe is running like a rabbit
s/\n//
replaces the newline character
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