Text Processing – Collapsing Multiple Lines into One

newlinestext processing

I have a file containing a a large number of lines, each of which contains a bunch of numbers which are separated by spaces. I process this data in a pipe in some way, and then I want to collapse the multiple lines into a single line of all the numbers separated by spaces.

Is there a standard command-line utility I can use to do this? It seems like most line-by-line utilities won't mess with the newlines…

Best Answer

That's why you don't use line-by-line utilities for this.

$ tr '\n' ' ' < input.txt > output.txt
Related Question