Compare a common field in two files and append a column from File 1 in File2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare a common field in two files and append a column from File 1 in File2
# 1  
Old 04-26-2012
Compare a common field in two files and append a column from File 1 in File2

Hi Friends,
I am new to Shell Scripting and need your help in the below situation.
- I have two files (File 1 and File 2) and the contents of the files are mentioned below.
- "Application handle" is the common field in both the files.

(NOTE :- PLEASE REFER TO THE ATTACHMENT "Compare files and Append values.txt" WITHIN THE POST FOR BETTER READABILITY)

File 1:
-------
Application handle = 3933
Client login ID = abcd
Application handle = 3932
Client login ID = efgh
Application handle = 5853
Client login ID = ijkl
Application handle = 5287
Client login ID = mnop
Application handle = 3938
Client login ID = qrst

File 2:
-------
==============================================================================================================================================================
APPLICATION_HANDLE STMT_TEXT
==============================================================================================================================================================
3933 SELECT EMPID,EMPNAME,EMPADD
FROM EMPLOYEE
WHERE EMPID=101
3932 -
5853 -
5287 INSERT INTO ADDRESS (SELECT CITY, STATE,COUNTRY
FROM EMP_ADDRESS
WHERE BIRTHCITY='XYZ'
3938 -
==============================================================================================================================================================
REQUIREMENT :
-------------
- Create a new Column with header - "Client login ID" in File 2
- Compare each "Application handle" between File1 and File2.
- For the matching "Application handle", print the corresponding "Client login ID" from File1 in File 2 under the new Column header - "Client login ID".

REQUIRED OUTPUT :
-----------------
==============================================================================================================================================================
CLIENT_LOGIN_ID APPLICATION_HANDLE STMT_TEXT
==============================================================================================================================================================
abcd 3933 SELECT EMPID,EMPNAME,EMPADD
FROM EMPLOYEE
WHERE EMPID=101
efgh 3932 -
ijkl 5853 -
mnop 5287 INSERT INTO ADDRESS (SELECT , STATE , COUNTRY
FROM EMP_ADDRESS
WHERE BIRTHCITY='XYZ'
qrst 3938 -
==============================================================================================================================================================
Thanks in advance !

Last edited by Santoshbn; 04-26-2012 at 02:08 AM.. Reason: The post was not easily readable. Table structure got jumbled.
# 2  
Old 04-26-2012
Please try searching the forum.
Similar question has been answered.
# 3  
Old 04-26-2012
Santoshbn@

Post what have you tried so far.
You have just posted the question alone. This is not an answer service, its a forum where you have to show what have you tried, so that others can chime in to provide any help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

How to append two files(file1 and file2) Please help me?

Hi I have two files file1 and file2 File1 10,000 entries:It has 3 columns below. conn=232257 client=xxx.xxx.xx.xxx:60491 protocol=LDAP File2 has 500 entries It has two columns. conn=232257 dn="uid=xxxx,ou=xxxx,ou=xxxx,dc=xxxxx,dc=xxxx" conn=232398... (10 Replies)
Discussion started by: buzzme
10 Replies

3. Shell Programming and Scripting

Compare multiple files, identify common records and combine unique values into one file

Good morning all, I have a problem that is one step beyond a standard awk compare. I would like to compare three files which have several thousand records against a fourth file. All of them have a value in each row that is identical, and one value in each of those rows which may be duplicated... (1 Reply)
Discussion started by: nashton
1 Replies

4. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

7. UNIX for Dummies Questions & Answers

compare two files based on common field in unix

I have two files in UNIX. 1st file is Entity and Second File is References. 1st File has only one column named Entity ID and 2nd file has two columns Entity ID | Person ID. I want to produce a output file where entity id's are matching in both the files. Entity File 624197 624252 624264... (4 Replies)
Discussion started by: PRS
4 Replies

8. Shell Programming and Scripting

How to compare data from 2 zip files and capture the new records from file2 to a new file

I have 2 zip files which have about 20 million records in each file. file 2 will have additional records than file 1. I want to compare the records in both the files and capture the new records from file 2 into another file file3. Please help me with a command/script which provides me the desired... (8 Replies)
Discussion started by: koneru
8 Replies

9. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

10. Shell Programming and Scripting

How to append two files with common field.

I have two files like File1 : will get this file from "who" command. It is a unix file. user val1 Jul 29 13:15 (IP Address1) user val3 Jul 30 03:21 (IP Address2) user val2 Jul 29 13:16 (IP Address3) user val4 Jul 29 13:17 (IP Address4) ... (4 Replies)
Discussion started by: manneni prakash
4 Replies
Login or Register to Ask a Question