adding a new line character to a row

Aron

I'd like to extract the 2nd field and transpose it to become a row

cat > temp1
1   73
2   74
3   75

My approach :

cut -f2 temp1 | tr '\n'  '\t' > temp2

The result :

temp2
73  74  75  

Understandably, there is a tab separator at the right end of the line but missing a new line character. Is there an simple one-liner to fix this?

glenn jackman

Use paste instead of tr:

$ cut -f2 temp1 | paste -s
73  74  75

verifying the invisible whitespace

$ cut -f2 temp1 | paste -s | od -c
0000000   7   3  \t   7   4  \t   7   5  \n
0000011

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related