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
how to extract columns from a text file ihot Shell Programming and Scripting 16 05-05-2008 08:33 PM
merging text files code19 Shell Programming and Scripting 8 02-13-2008 05:13 AM
Extract text in 2 columns of output file. Danish Shakil Shell Programming and Scripting 2 10-19-2007 07:03 AM
Extracting columns from different files for later merging kingkong UNIX for Dummies Questions & Answers 2 11-23-2005 12:21 AM
searching text files on specific columns for duplicates Gerry405 UNIX for Dummies Questions & Answers 2 08-18-2005 07:51 AM

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

Join Date: Aug 2005
Posts: 5
Exclamation merging few columns of two text files to a new file

hi

i need to select a few columns of two txt files and write it to a new file. there is one common field for both of these files.

plz help me in this

thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 09-14-2005
Registered User
 

Join Date: May 2005
Posts: 49
Hi,
Can you explain with an example?

Shihab
Reply With Quote
  #3  
Old 09-14-2005
Registered User
 

Join Date: Aug 2005
Posts: 5
i have 2 files with columns like :

file 1

x1,y1, z1


file 2
a1,b1,x1,c1,d1,e1


now i want the output as

b1,y1,c1,d1 for all the x1 of file1 in x1 of file2

i want to new file to be a merger of file1 and file 2 as explained above
Reply With Quote
  #4  
Old 09-14-2005
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
You can use the join command.
The two files (file1 and file2) must be sorted on the common field x1.

Code:
join -t , -1 1 -2 3 -o file1 file2 > file 3
-t , : , is field separator
-1 1 : join files using field 1 in file 1
-2 3 : join files using field 2 in file 2
-o 2.2,1.2,2.4,2.5 : list of resulting files (filenumber.field,...)



Jean-Pierre
Reply With Quote
  #5  
Old 09-15-2005
Registered User
 

Join Date: Aug 2005
Posts: 5
Thanks Jean, it worked prefect!!!!
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 05:01 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