When we want to replace the new line character \n
with the space:
xargs < file
xargs
has own limits on the number of characters per line and the number of all characters combined, but we can increase them. Details can be found by running this command: xargs --show-limits
and of course in the manual: man xargs
When we want to replace one character with another exactly one character:
tr '\n' ' ' < file
When we want to replace one character with many characters:
tr '\n' '~' < file | sed s/~/many_characters/g
First, we replace the newline characters \n
for tildes ~
(or choose another unique character not present in the text), and then we replace the tilde characters with any other characters (many_characters
) and we do it for each tilde (flag g
).