Home Man
Search
Today's Posts
Register

All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Columns to Rows

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 07-12-2012
Columns to Rows

I want to create a script with gawk.

I have the following file with 2 columns:


Code:
A 1 
A 2
A 3
B 1
B 2
B 3
C 1
C 2
D 1
D 2
D 3
D 4

and i want to convert to:

Code:
A 1 2 3
B 1 2 3 
C 1 2
D 1 2 3 4

Thanks in advance.

BR,
Sameer
Moderator's Comments:
Columns to Rows Code tags for code, please.

Last edited by Corona688; 07-12-2012 at 05:01 PM..
# 2  
Old 07-13-2012
Hi


Code:
$ gawk '$1==x{y=y FS $2;next}{if(y)print y;x=$1;y=$1 FS $2;}END{print y;}' file
A 1 2 3
B 1 2 3
C 1 2
D 1 2 3 4

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rows to columns jimmyf UNIX for Beginners Questions & Answers 6 01-09-2017 01:56 PM
Compare 2 csv files by columns, then extract certain columns of matcing rows bkane3 Shell Programming and Scripting 5 06-04-2014 04:29 AM
Columns and rows shelllearner Shell Programming and Scripting 3 03-20-2014 05:43 AM
Columns to rows apenkov Shell Programming and Scripting 11 11-27-2013 07:27 PM
Evaluate 2 columns, add sum IF two columns match on two rows mtucker6784 Shell Programming and Scripting 6 08-07-2013 12:57 PM
Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks ks_reddy Shell Programming and Scripting 4 02-04-2013 04:37 AM
Rows into Columns greycells Shell Programming and Scripting 1 05-08-2011 11:57 PM
rows to columns suresh3566 Shell Programming and Scripting 3 03-10-2011 03:54 AM
Columns into rows Ramya_1104 Shell Programming and Scripting 1 05-17-2010 04:10 AM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 06:03 PM


All times are GMT -4. The time now is 02:35 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password