The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Merge Two Files based on First column apjneeraj Shell Programming and Scripting 10 04-13-2009 01:44 AM
concatenate files with identifier yonhk UNIX for Dummies Questions & Answers 1 11-16-2008 10:51 PM
Merging column files swapna321 Shell Programming and Scripting 1 06-27-2008 07:12 AM
Merging two files with a common column manneni prakash Shell Programming and Scripting 2 06-20-2008 03:19 AM
merging two files based on some key Vandana Yadav Shell Programming and Scripting 1 02-03-2006 09:45 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 06-12-2009
phil_heath phil_heath is offline
Registered User
  
 

Join Date: May 2009
Posts: 57
merging column from two files based on identifier

Hi,

I have two files consisting of two columns. So I want to merge column 2 if column 1 is the same. So heres an example of what I mean.

FILE1

driver 444
car 333
hat 222

FILE2

driver 333
car 666
hat 999

So I want to merge the column 2's together so there is no gap... so the output file will look like this...

driver 444333
car 333666
hat 222999

Currently I am using this script but I can only get it to work for column 2 if column 1 is removed.

awk 'NR==FNR { a[c=FNR]=$0; next } { printf "%-8s%s\n", a[FNR], $0 } END { for(i=FNR+1;i<=c;i++) print a[i] }' FILE2.txt FILE2.txt > output.txt

Last edited by phil_heath; 06-12-2009 at 12:51 AM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0