![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
see man pages for join command
Gaurav |
|
#3
|
|||
|
|||
|
hi!
Quote:
|
|
#4
|
||||
|
||||
|
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
|
|||
|
|||
|
use the following
Quote:
|
|
#6
|
|||
|
|||
|
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
|
|||
|
|||
|
Quote:
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 |
|||
| Google The UNIX and Linux Forums |