sed delete newline

From thelinuxwiki
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