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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk script problem 1

Status
Not open for further replies.

ianicr

IS-IT--Management
Nov 4, 2003
230
GB
I have an awk script to check one file against another and print if the field doesn't match and go to another file 'removed' if it is:
BEGIN {
FS = ","
while ((getline < &quot;tps_ns.txt&quot;) >0)a[$0] = 1
phfld = 10
}
{
if (!a[$phfld]) print
else print >&quot;removed&quot;
}
Is there a way to make it check another field aswell ie. if both fields match then go to another file?
Thanks
 
Something like this, perhaps

BEGIN {
FS = &quot;,&quot;
while ((getline < &quot;tps_ns.txt&quot;) >0)a[$0] = 1
while ((getline < &quot;second_file.txt&quot;) >0)b[$0] = 1
phfld1 = 10
phfld2 = other_field_to_check
}
{
if (!a[$phfld1] || !b[phfld2]) print
else print >&quot;removed&quot;
}


CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Nope that didn't work. I'm really stuck on this... Can I just use one file with the awk eg.
1, DE4 6HJ
4, DE5 687

Then use this against a huge file of names and addresses to pull out just the record that have 1 in the 3rd field and DE4 6HJ in the last field and another record that has 4 in the 3rd field and DE5 687 in the last field? Any help would be muchly appreciated.
Thanks
 
Not sure if I understand exactly what you want, but maybe this will help you.

BEGIN {
FS=&quot;,&quot;
while ((getline < &quot;tps_ns.txt&quot;) > 0) a1[$1,$2] = 1
}
{
if (a1[$3,$NF]) print
}


CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Thank you sooooo much. Thats just what I needed!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top