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 > Operating Systems > 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 10:32 PM
Combining Two Files stevefox Shell Programming and Scripting 4 02-20-2006 05:09 AM
Combining Two Files bat711 Shell Programming and Scripting 3 10-05-2005 01:26 PM
Combining files Enda Martin UNIX for Dummies Questions & Answers 2 07-20-2001 10:31 AM
combining files apalex UNIX for Dummies Questions & Answers 3 06-19-2001 09:49 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 02-28-2006
d3ck_tm d3ck_tm is offline
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 03:29 AM.. Reason: typographical error
  #2 (permalink)  
Old 02-28-2006
gauravgoel gauravgoel is offline
Registered User
  
 

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


Gaurav
  #3 (permalink)  
Old 02-28-2006
d3ck_tm d3ck_tm is offline
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.
  #4 (permalink)  
Old 02-28-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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";
                } 
        }
}
  #5 (permalink)  
Old 02-28-2006
gauravgoel gauravgoel is offline
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
  #6 (permalink)  
Old 02-28-2006
gauravgoel gauravgoel is offline
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
  #7 (permalink)  
Old 02-28-2006
d3ck_tm d3ck_tm is offline
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
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:43 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