Table of Contents

Linux Commands : tr

Example

Replace line breaks to a specific character

# cat test.txt
aaaaaaaaa
bbbbbbbbb
ccccccccc
ddddddddd
eeeeeeeee
#
# cat test.txt | tr '\n' ','
aaaaaaaaa,bbbbbbbbb,ccccccccc,ddddddddd,eeeeeeeee,#
#
#

Remove line breaks

# cat test.txt
aaaaaaaaa
bbbbbbbbb
ccccccccc
#
# cat test.txt |tr -d '\n'
aaaaaaaaabbbbbbbbbccccccccc#
#

Convert continuous space to a single space

# cat test1.txt
1  2     3    4     5
a  b     c    d     e
# cat test1.txt |tr -s ' '
1 2 3 4 5
a b c d e
#