The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Combining two files hemangjani Shell Programming and Scripting 7 06-13-2007 07:32 PM
Combining Two Files stevefox Shell Programming and Scripting 4 02-20-2006 02:09 AM
Combining Two Files bat711 Shell Programming and Scripting 3 10-05-2005 10:26 AM
Combining files Enda Martin UNIX for Dummies Questions & Answers 2 07-20-2001 07:31 AM
combining files apalex UNIX for Dummies Questions & Answers 3 06-19-2001 06:49 AM

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

Join Date: Feb 2006
Posts: 9
combining two input text files

hi!

i would like to process two input text files

text1

9835023 20051004F2_011
9835021 20060904FAL0132006
8835099 20051004HOL011
8835044 20051004H1_011
6835023 20061002HAL0132006
4835099 20050721F1_011
4835088 20050906F1_011
4835044 20060905FAL0132006
4835023 20061001HAL0132006
4835021 20050816FAL011
3835023 20050707F1_011
2835021 20050531SM2011

text2

20050531SM2011
20050707F1_011
20050721F1_011
20050816FAL011
20050906F1_011
20051004F2_011
20051004H1_011
20051004HOL011

what i would like to happen is to combine those two, if text2 find its match in text1 (please see below)

final combination (output)

text3

9835023 20051004F2_011 20051004F2_011
9835021 20060904FAL0132006
8835099 20051004HOL011 20051004HOL011
8835044 20051004H1_011 20051004H1_011
6835023 20061002HAL0132006
4835099 20050721F1_011 20050721F1_011
4835088 20050906F1_011 20050906F1_011
4835044 20060905FAL0132006
4835023 20061001HAL0132006
4835021 20050816FAL011 20050816FAL011
3835023 20050707F1_011 20050707F1_011
2835021 20050531SM2011 20050531SM2011

i would like to know the proper coding for this
thanks for the help -->in advance
-d3ck_tm

Last edited by d3ck_tm; 02-28-2006 at 12:29 AM. Reason: typographical error
Reply With Quote
Forum Sponsor
  #2  
Old 02-28-2006
Registered User
 

Join Date: Dec 2005
Location: India
Posts: 218
see man pages for join command


Gaurav
Reply With Quote
  #3  
Old 02-28-2006
Registered User
 

Join Date: Feb 2006
Posts: 9
hi!

Quote:
Originally Posted by gauravgoel
see man pages for join command


Gaurav
i tried the JOIN command but it seems its not working... i guess its with the proper flags to be use.
Reply With Quote
  #4  
Old 02-28-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Havnt looked at join yet. I think it should be possible. Anyway here is perl script.

Code:
#! /usr/local/bin/perl 

$text1 = open (TEXT1,"< text1");
$text2 = open (TEXT2,"< text2");

%txt1 = ();

while ( chomp($line = <TEXT2>)) {
        $txt1{"$line"} = " ";
}

while ( chomp($line = <TEXT1>)) {
        if ($line =~ m/(\d+) (.*)/) {

                if ( exists $txt1{$2} ) {
                        print "$line $2 \n";
                }
                else {
                        print "$line \n";
                } 
        }
}
Reply With Quote
  #5  
Old 02-28-2006
Registered User
 

Join Date: Dec 2005
Location: India
Posts: 218
use the following

Quote:
join -1 2 -2 1 -o 1.1 1.2 2.1 -a 1 f1.txt f2.txt
Reply With Quote
  #6  
Old 02-28-2006
Registered User
 

Join Date: Dec 2005
Location: India
Posts: 218
hey i forgot one important thing sort the two files before joining them using sort command on field 2 of file 1 and filed1 of file 2.
Otherwise the join will not work properly.

Gaurav
Reply With Quote
  #7  
Old 02-28-2006
Registered User
 

Join Date: Feb 2006
Posts: 9
Quote:
Originally Posted by gauravgoel
hey i forgot one important thing sort the two files before joining them using sort command on field 2 of file 1 and filed1 of file 2.
Otherwise the join will not work properly.

Gaurav
Hi thanks for the syntax about the JOIN command, it worked.

My concern now is about the input file format.

When I joined the two files.

text1

9835023 20051004F2_011
9835021 20060904FAL0132006
8835099 20051004HOL011
8835044 20051004H1_011
6835023 20061002HAL0132006
4835099 20050721F1_011
4835088 20050906F1_011
4835044 20060905FAL0132006
4835023 20061001HAL0132006
4835021 20050816FAL011
3835023 20050707F1_011
2835021 20050531SM2011

text2

20050531SM2011
20050707F1_011
20050721F1_011
20050816FAL011
20050906F1_011
20051004F2_011
20051004H1_011
20051004HOL011

Actually file text1 have format, field1 and field2 suppose to have 20 charaters including the spaces.

X = represents spaces
9835023XXXXXXXXXXXXX20051004F2_011XXXXXX

questions:
1. can the JOIN command consider the spaces set in text1 file?
2. do i have to use some flags for this? Please let me know.

My goal is to have an output like this(below)

X = represents spaces
9835023XXXXXXXXXXXXX20051004F2_011XXXXXX20051004F2_011XXXXXX



thanks for your help

cheers!
--d3ck_tm
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:40 PM.


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