Removing Line Breaks

Sometime in scripting you don't get to choose your input format. For example, you might get data in multiple lines when you actually need it all in a single line. For such occasions you can go with:

cat file | awk '{printf "%s", $0}'

Likewise you might want lines separated by a space. Slight modification makes it happen:

cat file | awk '{printf "%s ", $0}'

Lastly, you might want to split a single line into multiple ones (handy for base64 printouts):

cat file | fold -w 72

PS: Check fmt if you need word-aware line splitting.

Leave a Reply

Your email address will not be published. Required fields are marked *