Transpose from 2nd column till the last column

Hi

I have 5 columns like this

a b c d e
f g h i j
k l m n o

From 2nd column till the 5th column of every record, I would like to transpose them as rows, so my output file contains only one row

a
b
c
d
e
f
g
h
i
j
k
l
m
n
o

Thanks

I tried this

echo "a b c d e
f g h i j
k l m n o" | tr ' ' '\n'

gave me the expected results :slight_smile:

1 Like

Thanks Pikk45, but my input file has more than 2000 columns.

So? tr doesn't care. It just deals char by char, so it can handle rows and columns of any size.

Is this taking too much to print??

try sed -e 's/\s/\n/g' file

That's ironic, since sed may have problems with huge lines, but tr never will!

1 Like

Thanks for the information :slight_smile:

Thanks to all of you. I used cat and then used the tr command from Pikk. It worked.

Useless cat :frowning: you could have used directly

tr ' ' '\n' < file

Another approach learned from Scrutinizer:

xargs -n1 < file