Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-20-2012
Registered User
 
Join Date: Feb 2012
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
Merge rows with common column

Dear all
I have big file with two columns

Code:
         A_AA960715   GO:0006952        
A_AA960715   GO:0008152 
        A_AA960715   GO:0016491         
A_AA960715   GO:0007165         
A_AA960715   GO:0005618 
        A_AA960716   GO:0006952        
A_AA960716   GO:0005618         
A_AA960716   GO:0055114         
A_AA960716   GO:0032440         
A_AA960716   GO:0016023         
A_AA960716   GO:0016310

and I need to have output file

Code:
         A_AA960715    GO:0006952   GO:0008152    GO:0016491    GO:0007165    GO:0005618    
  
       A_AA960716     GO:0006952   GO:0005618    GO:0055114    GO:0032440    GO:0016023    GO:0016310    GO:0016301    GO:0007165

I already tried the commands given by Otheus but it didn't work for me,
please help me urgently

Regards

Last edited by Scott; 02-20-2012 at 08:29 AM.. Reason: Code tags
Sponsored Links
    #2  
Old 02-20-2012
rangarasan's Avatar
Registered User
 
Join Date: Jul 2011
Location: Chennai, India
Posts: 484
Thanks: 9
Thanked 119 Times in 115 Posts
we have one file and what about the othere file to take the common column and additional column to merge ?

we have two files right ?
Cheers,
Ranga
Sponsored Links
    #3  
Old 02-20-2012
Registered User
 
Join Date: Feb 2012
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
Dear Ranga,

this is one text file with two columns

Code:
A_AA960715              GO:0006952        
A_AA960715             GO:0008152 
        A_AA960715              GO:0016491         
A_AA960715             GO:0007165

and I need to have new file with two columns where all the values corresponding to one value must be in row and in first column there must not the repetition of value, like this

Code:
A_AA960715                   GO:0006952   GO:0008152    GO:0016491    GO:0007165    GO:0005618

I think you its clear now
thanks

Last edited by Scott; 02-20-2012 at 08:30 AM.. Reason: Code tags
    #4  
Old 02-20-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,145
Thanks: 3
Thanked 957 Times in 936 Posts

Code:
awk '{a[$1]=a[$1]" "$2}END{for (i in a) print i" "a[i]}' file

Sponsored Links
    #5  
Old 02-20-2012
Registered User
 
Join Date: Feb 2012
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
Thanks Bartus,

but I got this error

Code:
$ awk '{a[$1]=a[$1]" "$2}END{for (i in a) print i" "a[i]}' file
awk: fatal: cannot open file `file' for reading (No such file or directory)

actually I am new to these commands,
please help me

regards

Last edited by Scott; 02-20-2012 at 08:30 AM.. Reason: Please use code tags
Sponsored Links
    #6  
Old 02-20-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,145
Thanks: 3
Thanked 957 Times in 936 Posts
"file" is the filename of the big file... I don't know what it is in your case...
Sponsored Links
    #7  
Old 02-20-2012
Registered User
 
Join Date: Feb 2012
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
yes I gave the name of file GO.txt it was, but the error was that ,
please tell me what to do then,,
thanks
Sponsored Links
Closed 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
Writing a loop to merge multiple files by common column evelibertine UNIX for Dummies Questions & Answers 1 10-07-2011 11:20 AM
merge two text files of different size on common index LMHmedchem Shell Programming and Scripting 8 05-01-2011 08:45 PM
"Join" or "Merge" more than 2 files into single output based on common key (column) Katabatic Shell Programming and Scripting 1 05-20-2010 11:41 AM
merge rows based on a common column smriti_shridhar Shell Programming and Scripting 6 10-17-2008 06:15 AM
merge based on common, awk help jkl_jkl Shell Programming and Scripting 3 03-17-2008 07:13 AM



All times are GMT -4. The time now is 04:59 AM.