by default only operates on single lines at a time. It takes a line into it's pattern buffer, minus the newline, applies the given expressions to it, then re-adds the newline when printing out the results. So a simple "s///
" on its own can't ever affect multiple lines.
To do so requires telling sed
to store multiple lines into the buffer first, usually with the "N
" command. Then the substitution pattern can target the newline between them. everToulouse
showed you how it's done.
Here are a few useful sed references.
is generally the better option, though. Notice, however, that just deleting the newline characters means the lines get concatenated without any spaces between them. So this might be closer to what you expect:
tr -s '\n' ' ' <file
option "squeezes" multiple newlines into a single space, so any blank lines will be removed. Remove it if not needed.