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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a date as a first column figaro UNIX for Dummies Questions & Answers 2 05-21-2008 02:00 PM
Help in adding positive & negative values in a column berlin_germany Shell Programming and Scripting 4 02-09-2007 02:03 PM
Adding a column of numbers Khoomfire UNIX for Advanced & Expert Users 1 01-18-2006 01:55 AM
adding a column at the end of the record pavan_test UNIX for Dummies Questions & Answers 2 11-07-2005 08:39 AM
Changing the column for a row in a text file and adding another row aYankeeFan Shell Programming and Scripting 9 05-02-2005 06:42 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-09-2006
Registered User
 

Join Date: Jun 2006
Posts: 29
FILE:Adding new column

Is it possible to add a new column in a file by matching a key element in second file ?

File 1
2 a
3 b
4 d
5 g
6 j
7 m


File 2


4 hjjjj
5 aaa
6 sasa
7 dsds
2 dsdf
3 fdsfg


we need to add 2nd coulmn of first file as the new column in second file by matching the first columns in both files. (First Column is like a foreign key in the case of databases)

Output File

4 hjjjj d
5 aaa g
6 sasa j
7 dsds m
2 dsdf a
3 fdsfg b

Please help in this regard.
Reply With Quote
Forum Sponsor
  #2  
Old 06-09-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Sort the files:

Code:
sort file1.txt > file1.new.txt
sort file2.txt > file2.new.txt
Then use "join":

Code:
join file2.new.txt file1.new.txt
Output:
Code:
2 dsdf a
3 fdsfg b
4 hjjjj d
5 aaa g
6 sasa j
7 dsds m
Reply With Quote
  #3  
Old 06-09-2006
Registered User
 

Join Date: Jun 2006
Posts: 29
Thank you so much Glenn...
Came to know about join from you
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0