Unix/Linux Go Back    


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

Columns to Rows

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-12-2012
sameeribraimo sameeribraimo is offline
Registered User
 
Join Date: May 2012
Last Activity: 12 July 2012, 4:39 PM EDT
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
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..
Sponsored Links
    #2  
Old Unix and Linux 07-13-2012
guruprasadpr's Unix or Linux Image
guruprasadpr guruprasadpr is offline Forum Advisor  
Shrink...ing
 
Join Date: Jun 2009
Last Activity: 13 September 2017, 5:57 AM EDT
Location: India
Posts: 676
Thanks: 30
Thanked 215 Times in 214 Posts
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

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
# of rows and columns kylle345 Shell Programming and Scripting 3 07-02-2009 08:15 PM
Columns to rows mgirinath Shell Programming and Scripting 16 11-29-2007 06:03 PM



All times are GMT -4. The time now is 04:01 PM.