I am using
sed to remove the new line and replace with
<br> but I am not able to get the desired output.
find . -name $1 -print0 | xargs -0 sed -i '' -e 's|\n|ABC|g'
...but this doesn't work.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add
<br> while retaining the actual newline as well, you can just use the end-of-line marker
$ and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the
-i''; also the
-e is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/\n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|\n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.