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

How to check for previous occurence? 1

Status
Not open for further replies.

LovecraftHP

Programmer
Dec 3, 2002
15
CN
I'm new to AWK, but I was wondering if any of you might be able to help me with this:

I want to be able to check whether the value of a certain field (the field is the same for all the records) is different from any of the field values in previous records. So e.g., every record has 4 fields, and I want to be able to check the 3d field of every record, with the "3d fields" of the previous records.

I've been trying to solve it using arrays, but so far unsuccessfully.
 
nawk -f fields.awk field.txt

#------------- fields.awk
BEGIN {
field2check="3"
}

{
if (! ($field2check in arr))
arr[$field2check]=NR;
else
printf("WARNING [%d]: [%s] was last seen on line->[%d]\n", NR, $field2check, arr[$field2check]);

}

#------------- fields.txt
1 2 3 4
5 6 7 8
1 2 3 4
2 4 6 8
1 3 5 7
5 6 7 8 vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top