I have the following two files, HAVING the exact format, WITH pipe "|" AS the field delimitor.
Please help me out, what's wrong with my script?
Thanks.
WHAT I want IS:
IF ( ($1=="F" for both files) && ($2 OF File_1.dat equals $2 OF File_2.dat) )
THEN
print $5 in File_1.dat & File_2.dat
FI
IN my example, I need the output AS:
FORM 00093545798 00093545799
FORM 00093545798 00093545799
FORM 00093545800 00093545700
File_1.dat
F|FORM|LABEL 1|000710530|00093545700|
F|FORM|LABEL 1|000710530|00093545798|
F|FORM|LABEL 1|122800059|00093545798|
F|FORMWHI|LABEL 2|545693984|00093545798|
F|FORMWHI|LABEL 2|548682665|00093545798|
F|FORMWHI|LABEL 2|552890553|00093545798|
F|FORMWHI|LABEL 3|578664420|00093545798|
F|FORMCVS|LABEL 3|588640859|00093545798|
F|FORMCVS|LABEL 3|680304420|00093545798|
F|FORM8000|LABEL 4|591480012|50458030503|
F|FORM8000|LABEL 4|591480013|50458030503|
File_2.dat
F|FORM|LABEL 1|000710530|00093545799|
F|FORM|LABEL 1|122800059|00093545799|
F|FORMOLDWHI|LABEL 5|545693984|00093545799|
F|FORMOLDWHI|LABEL 5|548682665|00093545799|
F|FORMOLDWHI|LABEL 5|552890553|00093545799|
F|FORMOLDWHI|LABEL 5|578664420|00093545799|
F|FORMOLDWHI|LABEL 5|588640859|00093545799|
F|FORMOLDWHI|LABEL 5|680304420|00093545799|
P|FORM8000|LABEL 6|591480010|50458030512|
P|FORM8000|LABEL 6|591480010|50458030512|
But I got the following output AFTER USING the script following.
FORM 00093545798 00093545799
FORM 00093545798 00093545799
FORM 00093545798 00093545700
Please help me out, what's wrong with my script?
Thanks.
WHAT I want IS:
IF ( ($1=="F" for both files) && ($2 OF File_1.dat equals $2 OF File_2.dat) )
THEN
print $5 in File_1.dat & File_2.dat
FI
IN my example, I need the output AS:
FORM 00093545798 00093545799
FORM 00093545798 00093545799
FORM 00093545800 00093545700
File_1.dat
F|FORM|LABEL 1|000710530|00093545700|
F|FORM|LABEL 1|000710530|00093545798|
F|FORM|LABEL 1|122800059|00093545798|
F|FORMWHI|LABEL 2|545693984|00093545798|
F|FORMWHI|LABEL 2|548682665|00093545798|
F|FORMWHI|LABEL 2|552890553|00093545798|
F|FORMWHI|LABEL 3|578664420|00093545798|
F|FORMCVS|LABEL 3|588640859|00093545798|
F|FORMCVS|LABEL 3|680304420|00093545798|
F|FORM8000|LABEL 4|591480012|50458030503|
F|FORM8000|LABEL 4|591480013|50458030503|
File_2.dat
F|FORM|LABEL 1|000710530|00093545799|
F|FORM|LABEL 1|122800059|00093545799|
F|FORMOLDWHI|LABEL 5|545693984|00093545799|
F|FORMOLDWHI|LABEL 5|548682665|00093545799|
F|FORMOLDWHI|LABEL 5|552890553|00093545799|
F|FORMOLDWHI|LABEL 5|578664420|00093545799|
F|FORMOLDWHI|LABEL 5|588640859|00093545799|
F|FORMOLDWHI|LABEL 5|680304420|00093545799|
P|FORM8000|LABEL 6|591480010|50458030512|
P|FORM8000|LABEL 6|591480010|50458030512|
But I got the following output AFTER USING the script following.
FORM 00093545798 00093545799
FORM 00093545798 00093545799
FORM 00093545798 00093545700
Code:
#!/bin/awk -f
### Script Name: form.awk
### Usage: form.awk File_2.dat
BEGIN {
FS="|"
while (getline < "File_1.dat") {
FORMS[1]=$2 #[COLOR=red]I didn't figure out how. [/color]
NDC11[$2]=$5 ## Store Field 5 in ARRAY NDC11 using 2nd field as the subscript
}
}
#[COLOR=red]I don't know how to do it, so just hard-coded $1 == "F" here. [/color]
$1 == "F" && length(NDC11[$2])>0 {
print $2 , NDC11[$2], $5
}