Convert row to columns start from nth column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert row to columns start from nth column
# 1  
Old 08-05-2014
Convert row to columns start from nth column

Dear All,

We have input like this:

Code:
       161                                 57  1378   176  1392   262  1444   441  1548   538  1611   670  1684
       241                                 57  1378   208  1393   269  1447   444  1549   538  1610   677  1700
       321                                 61  1378   197  1391   269  1448     
       401                                 72  1377   194  1389   265  1444     
       481                                 79  1377   197  1390   269  1446     
       561                                 75  1377   186  1390   269  1446

Algoritm: Convert row to columns start from 2nd to end of column

expected result:

Code:
       161                                 57   1378   
       161                                 176  1392   
       161                                 262  1444   
       161                                 441  1548   
       161                                 538  1611   
       161                                 670  1684
       241                                 57   1378   
       241                                 208  1393   
       241                                 269  1447   
       241                                 444  1549   
       241                                 538  1610   
       241                                 677  1700
       321                                 61   1378   
       321                                 197  1391   
       321                                 269  1448    
       401                                 72   1377   
       401                                 194  1389   
       401                                 265  1444    
       481                                 79   1377   
       481                                 197  1390   
       481                                 269  1446    
       561                                 75   1377   
       561                                 186  1390   
       561                                 269  1446

Thanks for advance,

Attila
# 2  
Old 08-05-2014
Had you searched these fora for your problem, you might have come up with e.g. this.
# 3  
Old 08-05-2014
Hi RudiC,
Thanks for suggestion, but we need to print it into 3 columns. Any idea?

---------- Post updated at 02:58 AM ---------- Previous update was at 02:14 AM ----------

Solved:

Code:
awk '{ for(a=2; a<=NF; a+=2) print ($1, $a, $(a+1)) }'

# 4  
Old 08-05-2014
Attaboy!
# 5  
Old 08-05-2014
Hi All, I am new to this forum . I am struggling with one issue

I have record set like (fixed width file)
Code:
1HKG  BKK  20140425201
2HKG  BKK  20140425201
3HKG  BKK  20140425201
1SIN  KUL  20140414201
2SIN  KUL  20140414201
3SIN  KUL  20140414201
1HKG  BKK  20140427201
2HKG  BKK  20140427201
3HKG  BKK  20140427201
1HKG  BKK  20140424201
2HKG  BKK  20140424201
3HKG  BKK  20140424201
1CDG  PVG  20140414201
2CDG  PVG  20140414201
3CDG  PEK  20140414201
3PEK  PVG  20140415201
1YYZ  BLR  20140414201
2YYZ  BLR  20140414201
3YYZ  FRA  20140414201
3FRA  BLR  20140415201
1BKK  CDG  20140409201

so there will be only 1,2,3 value in first field i need to assign seq number and output like this

Code:
1 1HKG  BKK  20140425201
1 2HKG  BKK  20140425201
1 3HKG  BKK  20140425201
2 1SIN  KUL  20140414201
2 2SIN  KUL  20140414201
2 3SIN  KUL  20140414201
3 1HKG  BKK  20140427201
3 2HKG  BKK  20140427201
3 3HKG  BKK  20140427201
4 1HKG  BKK  20140424201
4 2HKG  BKK  20140424201
4 3HKG  BKK  20140424201
5 1CDG  PVG  20140414201
5 2CDG  PVG  20140414201
5 3CDG  PEK  20140414201
5 3PEK  PVG  20140415201
6 1YYZ  BLR  20140414201
6 2YYZ  BLR  20140414201
6 3YYZ  FRA  20140414201

Please help

Last edited by Don Cragun; 08-05-2014 at 06:29 AM.. Reason: Add missing CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Data from Column to Row

Hi FileA.txt E_TIM 16, ETE 15, EOND 26, EEC 81, E_1 un, E_2 un, E_3 un, E_4 284, E_TIM 17, ETE 15, EOND 29, EEC 82, E_1 un, E_2 un, E_3 un, E_4 249, (6 Replies)
Discussion started by: asavaliya
6 Replies

2. Shell Programming and Scripting

How to convert the row to column in Perl?

Dear Perl users, Could you help me how to convert from row to column if I've a case below: Linux 2014_01_24 CPU 10 Linux 2014_01_24 MEM 20 UNIX 2014_01_24 CPU 30 UNIX 2014_01_24 MEM ... (6 Replies)
Discussion started by: askari
6 Replies

3. Shell Programming and Scripting

Convert columns to row using awk

Hi I need to convert some columns form a html file to rows. I do manage to make it works without help (some proud :) ) For some reason the offline status is not in bold, so I do need to remove the <b> tag from the other field to make this to work. All fields are not needed, so I test and... (5 Replies)
Discussion started by: Jotne
5 Replies

4. Shell Programming and Scripting

convert row to column with respect of first column.

Input file A.txt :- C2062 -117.6 -118.5 -117.5 C5145 0 0 0 C5696 0 0 0 Output file B.txt C2062 X -117.6 C2062 Y -118.5 C2062 Z -117.5... (4 Replies)
Discussion started by: asavaliya
4 Replies

5. UNIX for Dummies Questions & Answers

Dividing all columns by the nth row

Hi All! if I have a file like this: 8 10 12 14 16 18 0 2 6 2 4 6 8 10 12 16 18 10 6 8 12 16 18 0 2 2 6 2 2 2 2 2 2 2 2 2 10 12 16 4 8 16 4 16 0 8 10 14 16 0 4 8 12 14 And I want to divide all the lines by line 4 for example... (6 Replies)
Discussion started by: cosmologist
6 Replies

6. Shell Programming and Scripting

Convert row to column

Hi, I have a file like this 50 1 2 1374438 50 1 2 1682957 50 5 2 1453574 50 10 2 1985890 100 1 2 737307 100 5 2 1660204 100 10 2 2148483 and I want to convert this by... (1 Reply)
Discussion started by: gvj
1 Replies

7. Shell Programming and Scripting

convert a column to row output?

Getting tired of cut-and-paste...so I thought I would post a question. how do I change this column output to a single row? from this: # vgdisplay -v /dev/vgeva05 | grep dsk | awk '{print $3}' /dev/dsk/c6t0d5 /dev/dsk/c11t0d5 /dev/dsk/c15t0d5 /dev/dsk/c18t0d5 /dev/dsk/c7t0d5... (8 Replies)
Discussion started by: mr_manny
8 Replies

8. Shell Programming and Scripting

Convert columns to single row

Hello all I have data like 1 2 3 4 5 I wish my output would be like 1,2,3,4,5 For this i have executed 'BEGIN {FS="\n"; ORS=","} {print $0}' test and got the output as 1,2,3,4,5, I do not want to have , at the end of 5. output should be like (5 Replies)
Discussion started by: vasuarjula
5 Replies

9. Shell Programming and Scripting

How to convert 2 column data into multiple columns based on a keyword in a row??

Hi Friends I have the following input data in 2 columns. SNo 1 I1 Value I2 Value I3 Value SNo 2 I4 Value I5 Value I6 Value I7 Value SNo 3 I8 Value I9 Value ............... ................ SNo N (1 Reply)
Discussion started by: ks_reddy
1 Replies

10. UNIX for Dummies Questions & Answers

convert matrix to row and columns

Dear Unix Gurus, I have a sample data set that looks like this y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 I want to open it up so that I get x1 y1 0.3 x2 y1 1.2 x3 y1 3.1 x4 y1 5.0 x1 y2 0.5 x2 y2... (3 Replies)
Discussion started by: tintin72
3 Replies
Login or Register to Ask a Question

Featured Tech Videos