Computing.Net > Forums > Programming > awk program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk program

Reply to Message Icon

Name: ssonu
Date: August 27, 2007 at 10:26:12 Pacific
OS: OS/2
CPU/Ram: p4
Comment:

Hi
I'm a begginer to awk. I need to know how to compare 2 files with similar data, just that file 1 holds few records as when file 2 holds many records.

File 1:

Arnold Kim
Mike Parris
Kris Shay

File 2:

Arnold Kim
Kevin Parker
Mike Parris
Ben Scott
Kris Shay

If the records match in these two files I wanna generate an output file
(file 3, with the matched records)
Arnold Kim
Mike Parris
Kris Shay

and another file (file 4 with unmatched data).

Kevin Parker
Ben Scott
Can you help me out.

ss



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: August 27, 2007 at 16:17:36 Pacific
Reply:

Are you sure this isn't homework? Anyway, take a look at this link

http://www.computing.net/unix/wwwbo...

James Booth shows you how to read a file into an awk array.


0

Response Number 2
Name: ghostdog
Date: August 27, 2007 at 23:20:04 Pacific
Reply:

Since you are a beginner, you should be reading up on awk, trying to do it yourself first before even posting in any forums. however, giving you the benefit of doubt, here's one way in awk.

[code]
awk 'FNR==NR{ arr[$0];next}
{if ($0 in arr) print $0 > "matched.txt"
else print $0 > "not_matched.txt"
}' "file" "file1"
[/code]


0

Response Number 3
Name: Guy
Date: August 29, 2007 at 14:18:12 Pacific
Reply:

It sounds like homework to me.

If you are really running OS2, you should be doing this in REXX, not Awk.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: awk program

Error IN AWK Programming www.computing.net/answers/programming/error-in-awk-programming/15662.html

shell programming www.computing.net/answers/programming/shell-programming/4443.html

awk program www.computing.net/answers/programming/awk-program/13748.html