The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2005
kolvi kolvi is offline
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
  #2 (permalink)  
Old 09-14-2005
shihabvk shihabvk is offline
Registered User
  
 

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

Shihab
  #3 (permalink)  
Old 09-14-2005
kolvi kolvi is offline
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
  #4 (permalink)  
Old 09-14-2005
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
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
  #5 (permalink)  
Old 09-15-2005
kolvi kolvi is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 5
Thanks Jean, it worked prefect!!!!
Closed Thread

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 05:12 AM.


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