To transpose row into column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To transpose row into column
# 8  
Old 01-14-2014
Did you try #5 and #6 ?

--edit--

Code:
$ awk '/[0-9]/' RS=" " tmp


Last edited by Akshay Hegde; 01-14-2014 at 10:44 AM..
# 9  
Old 01-14-2014
Hi Yodi,
Thanks for your one liner code. it worked perfectly..

One more tip if you may like to give me, say i have to present the data in below format , what would be the awk code
Code:
5861.8
0.026
0.012
12.584
0.026
0.012
12.582
0.000
0.000
0.000
351706

Moderator's Comments:
Mod Comment Use code tags, please!

Last edited by radoulov; 01-14-2014 at 10:52 AM..
# 10  
Old 01-14-2014
change loop make { for(i=3;i<=NF;i++)....}
This User Gave Thanks to Akshay Hegde For This Post:
# 11  
Old 01-14-2014
Code:
xargs -n1 <yourfile

This User Gave Thanks to ctsgnb For This Post:
# 12  
Old 01-17-2014
Hello,

Here are some more approaches are there.

1st:
Code:
cat change_row_row1 | tr ' ' '\n' | grep -v '^$'

2nd:
Code:
perl -p -e 's/\s+/\n/g' change_row_row1 | grep -v '^$'


Output will be as follows in both conditions.

Code:
351706
5861.8
0.026
0.012
12.584
0.026
0.012
12.582
0.000
0.000
0.000


Thanks,
R. Singh
# 13  
Old 01-17-2014
Thanks
Code:
$ cat tmp
575732 159.93 0.012 0.005 0.297 0.012 0.004 0.297 0.000 0.000 0.006 0.001 0.000 0.017

Code:
$ awk '{for(i=1;i<=NF;i++) print $i}' tmp

Code:
575732
159.93 ----I have issue like i want 159.93 value to be printed at last row of column 
0.012
0.005
0.297
0.012
0.004
0.297
0.000
0.000
0.006
0.001
0.000
0.017

the above highlighted data <159.93> should be at this location

Expected Results should be as follows:
Code:
575732
0.012
0.005
0.297
0.012
0.004
0.297
0.000
0.000
0.006
0.001
0.000
0.017
159.93


Last edited by Franklin52; 01-17-2014 at 03:17 AM.. Reason: add code tags
# 14  
Old 01-17-2014
Quote:
Originally Posted by Anamica
Thanks
Code:
$ cat tmp
575732 159.93 0.012 0.005 0.297 0.012 0.004 0.297 0.000 0.000 0.006  0.001 0.000 0.017

Code:
$ awk '{for(i=1;i<=NF;i++) print $i}'  tmp

Code:
575732
159.93 ----I have issue like i want 159.93 value to be printed at last row of column 
0.012
0.005
0.297
0.012
0.004
0.297
0.000
0.000
0.006
0.001
0.000
0.017

the above highlighted data <159.93> should be at this location

Expected Results should be as follows:
Code:
575732
0.012
0.005
0.297
0.012
0.004
0.297
0.000
0.000
0.006
0.001
0.000
0.017
159.93




Code:
$ awk '{last=$2;for(i=1;i<=NF;i++)if(i!=2)print $i;print last}' tmp

Code:
$ awk '{last=$2;for(i=1;i<=NF;i++)if(i!=2)print $i}END{print last}' tmp

Code:
$ awk '{last=$2; $2=""; $0=$0; $1=$1; for(i=1;i<=NF;i++)print $i;print last}' tmp

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Transpose the Row and column

Hi, I have data in form of A ram B shyam C seeta D geeta A bob B methew C Richad D Mike and i want it in this form. A B C D ram shyam seeta geeta bob methew Richard Mike. please help by providing the scripting for this. (3 Replies)
Discussion started by: ricbha
3 Replies

2. Shell Programming and Scripting

How transpose column in a row?

Hello guys, First of all happy holidays and happy new year. I'm new in bioinformatic and also it is my first time that I write in this forum. Therefore, sorry if I make some mistakes. I'm writing to ask your help to fix a problem: I have a file like this: gene1 GO:0016491|GO:0055114... (8 Replies)
Discussion started by: Salvatore_espos
8 Replies

3. Shell Programming and Scripting

Transpose from row to column using timestamp in first column

Gents, Transpose from row to column, taking in consideration the first column, which contends the date. Input file 72918,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009,111000009 72918,2356,2357,2358,2359,2360,2361,2362,2363,2364 72918,0,0,0,0,0,0,0,0,0... (12 Replies)
Discussion started by: jiam912
12 Replies

4. Shell Programming and Scripting

Transpose row to column

I'm using the testawk.awk from the following thread https://www.unix.com/shell-programming-and-scripting/18897-row-column-transpose.htmlI'm getting the following output fieldname1 data1 fieldname2 data2 fieldname3 data3 How can I get like this instead 1 fieldname1 data1 2 fieldname2 data2... (1 Reply)
Discussion started by: makkan
1 Replies

5. Shell Programming and Scripting

Transpose column to row - awk

Hi there, I have a small csv file example below: source,cu_001,cu_001_volume,cu_001_mass,cu_002,cu_002_volume,cu_002_mass,cu_003,cu_003_volume,cu_003_mass ja116,1.33,3024000,9374400,1.54,3026200,9375123,1.98,3028000,9385512 I want to transpose columns to rows starting at the second... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

6. Shell Programming and Scripting

Column to row Transpose

Hi Folks, Iam a kinda newbie to unix shell scripting, the scenario is i have a text file containing the following info Charlie chicago 15 Charlie newyork 26 jonny chicago 14 jonny newyork 15 joe chicago 15 joe newyork 18output should be Name chicago ... (3 Replies)
Discussion started by: tech_frk
3 Replies

7. UNIX for Dummies Questions & Answers

Row to column transpose

Hi there, Below is sample three rows which i need transpose into multiple rows. By keeping first 2 fields static and split them into multiple rows depend following date field. Each into seperate rows. Sample code: ... (6 Replies)
Discussion started by: ganeshd
6 Replies

8. Shell Programming and Scripting

Row to column transpose between same pattern.

Hi All, I have been trying to transpose rows to column in an large file (about 15000 lines) between matching pattern. Searched all posts in this forum, but not able find the solution to my problem. Any help appreciated.!! Input /*------XXXXXX-------*/ owner: XXXX location: XXXX... (3 Replies)
Discussion started by: RobP
3 Replies

9. Shell Programming and Scripting

Transpose column to row

Hi i have a file which has values seperated by "," as shown below and I want to transpose for every doc_id in one row. Input: DOC_ID,KEYWORD 105,REGISTROS 105,GEOLOGIA 105,NUCLEOS 105,EXPEDIENTE 105,PROGRAMAS 10025,EXPEDIENTE 10025,LOCALIZACIONES 10025,OFICIOS 10025,PROGRAMAS... (4 Replies)
Discussion started by: juelillo
4 Replies

10. Shell Programming and Scripting

Row to column transpose

Can we transpose rows to columns? Fields within row are separated by a comma. (10 Replies)
Discussion started by: videsh77
10 Replies
Login or Register to Ask a Question