Reputation: 1237
I need to substitute each \n in a line with "\n (double quote followed by newline).
This should work. But it does nothing. Reports no error either. Any clues anyone?
sed -i 's/\n/\"\n/' filename
before, the file contains:
line 1
line 2
after, it contains the exact same.
Thanks
Upvotes: 1
Views: 92
Reputation: 780724
A line can't contain \n
, because \n
is the delimiter between lines. sed
operates on a single line at a time, and the newline is not included in it.
If you want to put a character before the end of each line, use the $
regexp:
sed -i 's/$/"/' filename
Upvotes: 5
Reputation: 368944
Try following:
sed -i 's/$/"/' filename
used $
to denote end of the line.
Upvotes: 2