Skip to main content

adding a new line character to a row [Resolved]

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?


Question Credit: Aron
Question Reference
Asked October 10, 2018
Tags: shell, grep
Posted Under: Unix Linux
37 views
1 Answers

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

credit: glenn jackman
Answered October 10, 2018
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA