Suggestion to convert data in rows to data in columns


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Suggestion to convert data in rows to data in columns
# 1  
Old 03-30-2011
Suggestion to convert data in rows to data in columns

Hello everyone!
I have a huge dataset looking like this:
Code:
nameX nameX 0 1 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 ...............       
nameY nameY 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 .....
nameB nameB 0 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 .....
 (can be several thousands of codes)

and I need to get in output

Code:
nameX      nameY      nameB
nameX      nameY      nameB
0            2           0
1            2           1
2            2           2

Could you help in this? I am new (as many who asks for help) in unix
Thank you for ur time in advance
with regards
ksuh

Last edited by joeyg; 03-30-2011 at 01:51 PM.. Reason: Please use CodeTags to wrap data and commands
# 2  
Old 03-30-2011
Please note that I tried to reformat your data, since it looked like some formatting got lost in your posting. Please verify, as the input layout will have a big effect on solutions.
# 3  
Old 03-30-2011
Thank u for that quick fedback!! The input file presents itself
"name name' following by thousands figures then space then next "name name" following by figures (lets say one extra long row with spaces which separate "name name 0 2 0 1 2 2 1 .." blocks).
# 4  
Old 03-30-2011
Put this is a file - testawk.awk

Code:
{
for (i=1;i<=NF;i++)
{
 arr[NR,i]=$i;
 if(big <= NF)
  big=NF;
 }
}
 
END {
  for(i=1;i<=big;i++)
   {
    for(j=1;j<=NR;j++)
    {
     printf("%s\t",arr[j,i]);
    }
    printf("\n");
   }
}

awk -f testawk.awk testfile
This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 03-31-2011
Thanks a lot to rdcwayx!

The thing is that this commad you have written here works, but in the end im getting same file, unfortunately, i mean, again rows instead of columns (does it overwrite the initial file?).
thank u very much! and sorry if i have asked something wrong!
kush
# 6  
Old 04-01-2011
Take a look at this site, it has awk and perl solution.

https://www.unix.com/shell-programmin...using-awk.html
# 7  
Old 04-01-2011
Quote:
Originally Posted by kush
Thanks a lot to rdcwayx!

The thing is that this commad you have written here works, but in the end im getting same file, unfortunately, i mean, again rows instead of columns (does it overwrite the initial file?).
thank u very much! and sorry if i have asked something wrong!
kush
Code:
awk -f testawk.awk testfile > temp
mv temp testfile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data from specific rows and columns from multiple csv files

I have a series of csv files in the following format eg file1 Experiment Name,XYZ_07/28/15, Specimen Name,Specimen_001, Tube Name, Control, Record Date,7/28/2015 14:50, $OP,XYZYZ, GUID,abc, Population,#Events,%Parent All Events,10500, P1,10071,95.9 Early Apoptosis,1113,11.1 Late... (6 Replies)
Discussion started by: pawannoel
6 Replies

2. Shell Programming and Scripting

Transpose comma delimited data in rows to columns

Hello, I have a bilingual database with the following structure a,b,c=d,e,f The right half is in a Left to right script and the second is in a Right to left script as the examples below show What I need is to separate out the database such that the first word on the left hand matches the first... (4 Replies)
Discussion started by: gimley
4 Replies

3. Shell Programming and Scripting

Convert Column data values to rows

Hi all , I have a file with the below content Header Section employee|employee name||Job description|Job code|Unitcode|Account|geography|C1|C2|C3|C4|C5|C6|C7|C8|C9|Csource|Oct|Nov|Dec|Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep Data section ... (1 Reply)
Discussion started by: Hypesslearner
1 Replies

4. UNIX for Dummies Questions & Answers

Convert nxm Matrix into columns of data

Dear Unixers, I'm having some difficulty in converting an n x m data matrix into a dataset of 3 columns and nxm rows. As an example I want to convert this dataset 2 3 4 5 2 0.0 0.0 0.1 0.1 6 -0.3 2.0 0.0 0.3 7 -0.6 -1.1 0.5 0.3 9 -0.9 -4.1 -0.7 0.5 ... (2 Replies)
Discussion started by: tintin72
2 Replies

5. Shell Programming and Scripting

Transpose Data from Columns to rows

Hello. very new to shell scripting and would like to know if anyone could help me. I have data thats being pulled into a txt file and currently have to manually transpose the data which is taking a long time to do. here is what the data looks like. Server1 -- Date -- Other -- value... (7 Replies)
Discussion started by: Mikes88
7 Replies

6. Shell Programming and Scripting

Help for a Perl newcomer! Transposing data from columns to rows

I have to create a Perl script which will transpose the data output from my experiment, from columns to rows, in order for me to analyse the data. I am a complete Perl novice so any help would be greatly appreciated. The data as it stands looks like this: Subject Condition Fp1 ... (12 Replies)
Discussion started by: Sarah_W
12 Replies

7. UNIX for Dummies Questions & Answers

Convert Rows to Columns Specific Data

I have this data M36 AREA INFORMATION MDN = 0485009346 ESN = H'15fda0b0 TYPE = HLR RESULT = NOK REASON = UNRECOGNIZED MIN COMPLETED AREA INFORMATION MDN = 0498044402 ESN = H'15fdac11 TYPE... (2 Replies)
Discussion started by: krabu
2 Replies

8. Shell Programming and Scripting

Transpose columns to Rows : Big data

Hi, I did read a few posts on the subjects, tried out a few solutions, but did not solve my problem. https://www.unix.com/302121568-post11.html https://www.unix.com/shell-programming-scripting/137953-large-file-columns-into-rows-etc-4.html Please help. Problem very similar to the second link... (15 Replies)
Discussion started by: genehunter
15 Replies

9. Shell Programming and Scripting

Data in Rows to Columns

Hi, I am a beginner in bash&perl. I have data in form of:- A 1 B 2 C 3 D 4 E 5 I would like your help to find a simple way to change it to :- A B C D E 1 2 3 4 5 Any help would be highly appreciated. (8 Replies)
Discussion started by: umaars
8 Replies

10. Shell Programming and Scripting

Convert two column data into 8 columns

Apologies if this has been covered - I did search but couldn't find what I was looking for. I have a simple X-Y input file. I want to convert it from two columns into 8 columns - 4 pairs of X-Y data. So my input file looks like X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 etc And I want it to look... (8 Replies)
Discussion started by: NickC
8 Replies
Login or Register to Ask a Question