Newsgroups: comp.unix.shell Date: Fri, 14 Oct 2005 20:48:17 -0500
Newsgroups: comp.unix.shell Date: Fri, 14 Oct 2005 20:48:17 -0500
> How can I Transpose Column to Row Using Shell Script? > > Original File(there's only one column) > start > sp.val1 > sp.val3 > sp.val4 > sp.val5 > sp.val6 > sp.val9 > end > > To(there's only one row) > start sp.val1 sp.val3 sp.val4 sp.val5 sp.val6 sp.val9 end
As an alternative to the tr solution Chris posted:
{ tr '\012\015' ' ' < FILE; echo; } > newfile
there's always:
awk '$1=$1' RS= FILE > newfile
The main difference is that the awk solution will compress contiguous blank lines into a single blank character whereas the tr solution would result in multiple blank chars in the output.
Ed Morton
> The main difference is that the awk solution will compress contiguous > blank lines into a single blank character whereas the tr solution would > result in multiple blank chars in the output.
I'd still use tr (as the lighter alternative):
{ tr -s '\012\015' ' ' < FILE; echo; } > newfile
Chris F.A. Johnson
documented on: 2006.01.10