Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turn Colums into Rows

Status
Not open for further replies.

meetramana

Programmer
Feb 2, 2005
57
US
Hi all,

Can somebody suggest how do I turn colums into rows and rows into columns.

Example:

Data Name1 Name2
Data1 NAME1 NAME2

Result should look like

Data Data1
Name1 NAME1
Name2 NAME2
 
A starting point:
nawk '
{ for(i=1;i<=NF;++i) a[NR,i]=$i }
END{for(i=1;i<=NF;++i){
for(j=1;j<=NR;++j)printf "%s ",a[j,i]
printf "\n"
}}
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
How? RDBM, perl, bash, c-shell, c, Java....

Precise your query; greater chance of response...


 
chipperMDW, unfortunately the column command is not available in most *nix flavor ...
 
Correction:
chipperMDW, unfortunately the column command is not available in most SysV *nix flavor ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Good point.

If needed, here's a package containing the source code for, among other things, [tt]column[/tt]. It's targeted at Linux, but it attempts to be portable. Since the [tt]column[/tt] command just manpulates text, I expect it should work on other variants, too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top