combining two input text files


 
Thread Tools Search this Thread
Operating Systems AIX combining two input text files
# 1  
Old 02-28-2006
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  
Old 02-28-2006
see man pages for join command


Gaurav
# 3  
Old 02-28-2006
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  
Old 02-28-2006
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  
Old 02-28-2006
use the following

Quote:
join -1 2 -2 1 -o 1.1 1.2 2.1 -a 1 f1.txt f2.txt
# 6  
Old 02-28-2006
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  
Old 02-28-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Modifying/combining two text outputs

greetings, I have what seems to be a fairly complex task at hand. I am dealing with 3 outputs from a database. a) Listing of tables. The first 3 characters are always an identifier of an application. See in part b - Example- select tablename from system.tables ABC1 ABC2 RFV1 ... (2 Replies)
Discussion started by: jeffs42885
2 Replies

2. Shell Programming and Scripting

Copying a file to multiple other files using a text file as input

Hello, I have a file called COMPLIST as follows that contains 4 digit numbers.0002 0003 0010 0013 0015 0016 0022 0023 0024 0025 0027 0030 0031 0032 0033 0035 0038 0041 (3 Replies)
Discussion started by: sph90457
3 Replies

3. Shell Programming and Scripting

Formatting and combining fields of the input file

Hi, I have a file of the following format: AV 103 AV 104 AV 105 AV 308 AV 517 BN 210 BN 211 BN 212 BN 218 and the desired output is : AV 103-105 3 AV 308 1 AV 517 1 BN 210-212 3 (5 Replies)
Discussion started by: rochitsharma
5 Replies

4. UNIX for Dummies Questions & Answers

Need Help in reading N days files from a Directory & combining the files

Hi All, Request your expertise in tackling one requirement in my project,(i dont have much expertise in Shell Scripting). The requirement is as below, 1) We store the last run date of a process in a file. When the batch run the next time, it should read this file, get the last run date from... (1 Reply)
Discussion started by: dsfreddie
1 Replies

5. Shell Programming and Scripting

Combining rows in a text file with a character limit

I have a file that contains several thousands rows. Here is an example. ^411912$ ^487267$ ^643776$ ^682249$ ^687737$ ^692328$ ^693767$ ^695483$ ^697289$ ^757411$ ^776688$ ^778953$ ^806123$ ^872262$ ^877877$ ^839837$ ^76666$ ^72018$ ^23330$ (3 Replies)
Discussion started by: justinb_155
3 Replies

6. UNIX for Dummies Questions & Answers

Combining two text files as columns?

I have one space delimited file with multiple columns and one tab delimited file with multiple columns (They have the same number of rows). I want to basically combine these two text files into a new text file by column. How would I go about doing that? (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

8. Shell Programming and Scripting

Need help combining large number of text files

Hi, i have more than 1000 data files(.txt) like this first file format: 178.83 554.545 179.21 80.392 second file: 178.83 990.909 179.21 90.196 etc. I want to combine them to the following format: 178.83,554.545,990.909,... 179.21,80.392,90.196,... (7 Replies)
Discussion started by: mr_monocyte
7 Replies

9. Shell Programming and Scripting

Combining two text lines into one

Here is the sample file: 646 STARTED Tue Dec 30 06:38:53 2008 Job DdCustXAddr_brad has been reset. 647 STARTED Tue Dec 30 06:38:54 2008 Starting Job DdCustXAddr_brad. (...) 704 STARTED Tue Dec 30 06:49:02 2008 Job DdCustXAddr_brad aborted. I want to combine every non-numbered line... (4 Replies)
Discussion started by: mfavero
4 Replies

10. Shell Programming and Scripting

Merge text files while combining the multiple header/trailer records into one each.

Situation: Our system currently executes a job (COBOL Program) that generates an interface file to be sent to one of our vendors. Because this system processes information for over 100,000 employees/retirees (and growing), we'd like to multi-thread the job into processing-groups in order to... (4 Replies)
Discussion started by: oordonez
4 Replies
Login or Register to Ask a Question