I need awk to look at the first column of each file and if a field appears in core_extract that also appears in gmrd.txt then it should write append that line to a file
here is what i have so far...currently it replaces the line found with "TEST"
any help appreciated
awk '
BEGIN {
FS = OFS = ";"
while (getline < "core_extract.txt" > 0)
arr[$1] = 1
}
$1 in arr {
$0 = "TEST"
}
{print}
' gmrd.txt
however when I run that script it actually still leaves the output from core_extract.txt in the output - is there any way of just seeing the relevant records from gmrd.txt?
1 - is awk's shortcut of saying "true". When awk 'condition' [logically] evaluates to true it simply prints the current record. In your case it will print record/line from core_extract.txt.
The more explicit/equivalent way to do this would be:
seems like the SECOND field in BOTH files is NOT UNIQUE.
what gets printed out is the LAST row from gmrd for a given SECOND field.
seems like having ONLY the second field is NOT enough to identify records UNIQUELY. You might consider either using a DIFFERENT field and/or using a combination of fields from both files to do your "lookup".
is there anyway to overcome this as the only field common to both is the second field. would I have to create a variable out of the second fields in core.txt and then from that check gmrd.txt
The desired output would look at field three of core.txt and compare that with field three of gmrd.txt and only print those lines where gmrd.txt has the same field three value as core.txt so the output would be:
./temp4.sh[8]: awk^JBEGIN {^JFS=OFS=";"^J}^J^JFNR==NR { arr[$3]= ($3 in arr) ? a
rr[$3] "\n" $0 : $0; next }^J$3 in arr { print arr[$3] }^Jgmrd.txt: not found
could this be to do with the flavour of UNIX im using? (AIX)