sed delete newline

From thelinuxwiki
Revision as of 18:53, 2 April 2024 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

example of sed failing to remove newline...

$ printf "foo\nbar\n" | sed 's/\n//'
foo
bar

solution is to pass sed the -z or --null-data option to separate lines by NUL characters

$ printf "foo\nbar\n" | sed -z 's/\n//'
foobar