Difference between revisions of "Delete newline through pipe"

From thelinuxwiki
Jump to: navigation, search
(Pushed from Themanclub.)
 

Latest revision as of 04:06, 29 March 2013

tr — remove new line characters with tr

tr -d '\n' < days.txt
cat days.txt | tr -d '\n'

While the new line characters can be replaced with spaces using the tr program as follows.

tr '\n' ' ' < days.txt
cat days.txt | tr '\n' ' '

awk — remove new line characters with awk or gawk

Either of the following commands can be used to delete new lines using awk or gawk.

awk '{ printf "%s", $0 }' days.txt
cat days.txt | awk '{ printf "%s", $0 }'

While the new line characters can be replaced with spaces using either of the following commands.

awk '{ printf "%s ", $0 }' days.txt
cat days.txt | awk '{ printf "%s ", $0 }'