Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing multiple files with different fields. 3

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I am a novice awk programmer and this is my first and critical assignment.
I have two flat files as input.
File 1 : 1|xyz|111|perrysburg|21
2|abc|222|sylvania|21
3|pqr|121|toledo|21
4|wpr|112|annarbor|21
5|mno|131|detroit|21
6|hij|133|columbus|21
7|klm|333|cincinati|21

File 2 : 1|xyz|111|perrysburg|21
3|pqr|121|toledo|21
4|wpr|112|annarbor|21
6|hij|133|columbus|21
8|def|212|maumee|21

I would like to search on fields 1,2,4 in File1 with fields 1,2,4 from File2 and if there is a match then write the whole record of File2 to an output file1 else write the whole record of File2 to output file2.
Also,pl. remember that the file names and the column positions for the search need to be dynamic (user inputs).

Pl. help me ASAP.:-(

Thank you for your time.
 
Hi Grant,
I am sorry for the wrong info. Your code work greats for 1,2,4 columns (I got the same output as yours !!)
but I tried it with 1,3,4 and it did not gave me the correct output.
Heres what I did...
File1
=====
1|xyz|111|perrysburg|21
2|abc|222|sylvania|21
3|pqr|121|toledo|21
4|wpr|112|annarbor|21
5|mno|131|detroit|21
6|hij|133|columbus|21File2
=====
1|xyz|111|perrysburg|21
3|pqr|121|toledo|21
4|wpr|111|annarbor|21
6|hij|133|columbus|21
8|def|212|maumee|21

I changed the 3rd col of the 3rd row.
ran your script.

awk -f tek_tips.awk 1 3 4 file2 file1

The o/p is as follows...

Dups
====
1|xyz|111|perrysburg|21
3|pqr|121|toledo|21
4|wpr|112|annarbor|21 --This should not be here !!.
6|hij|133|columbus|21

No-Dups
=======
2|abc|222|sylvania|21
5|mno|131|detroit|21
7|klm|333|cincinati|21

Pl. help.
Thanks.
 
Hi baby_awk,

I see your point. I will check.

Grant.
 
Hi baby_awk,

I found the problem:

There are 2 lines that look like this:
ColStr=ColStr SUBSEP ColNo[j];

They should be:
ColStr=ColStr SUBSEP ColVal[j];


Try that and let me know how it goes,
Grant.
 
Hey Grant,

Absolutely Fantastic buddy !!!

IT WORKS !!!.

I OWE YOU A TREAT !!.

Thanks for all your efforts and help.
 
Grant,

get a star for perseverance! ;) vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Hi baby_awk,

I'm glad it's working the way you want. That was a tough assignment for a beginner. Now it's your job to maintain it, so I recommend you try to improve it. There's lots of room for improvement. For one thing you could reduce the routine to build the subscript to a function, and you could make it a bit more bulletproof.

Take care,

Note to vgersh99. Thanks! You must have had quite a bit of perseverance to read all the way to the bottom.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top