Problem with awk and if statement
Hi,
I have a task where i need to compare columns of two files.
First file is $REG_InputFileName:
"UPDATE","1010021126","1-01-01","USD"
"UPDATE","1013000101","1-01-01","THB"
"UPDATE","1013010107","1-01-01","THB"
"UPDATE","1110011122","1-01-01","USD"
"UPDATE","1110020111","1-01-01","THB"
"UPDATE","1110020111","1-01-01","USD"
"UPDATE","1110020113","1-01-01","THB"
"UPDATE","1620020409","1-01-01","USD"
"UPDATE","1620020612","1-01-01","USD"
"UPDATE","1620021126","1-01-01","USD"
"UPDATE","1910020411","1-01-01","USD"
"UPDATE","1910020722","1-01-01","USD"
"UPDATE","1910030021","1-01-01","THB"
"UPDATE","1910031191","1-01-01","THB"
"UPDATE","1910031221","1-01-01","THB"
"UPDATE","2620021162","1-01-01","USD"
Second file is $TargetSeqPath/Ref.tmp:
001.,ARE
002.,ARE
003.,ARE
011.,ARE
012.,ARE
021.,BHR
031.,BHR
041.,QAT
043.,QAT
051.,QAT
061.,OMN
071.,OMN
081.,LBN
091.,LBN
101.,JOR
111.,JOR
121.,EGY
131.,EGY
141.,MUS
151.,MUS
162.,IRQ
181.,PAK
191.,PAK
In this, i need to compare first three characters of 2nd column of $REG_InputFileName with first 3 characters 1st column of $TargetSeqPath/Ref.tmp
if there is match then the whole record should go to a file which is in the directory named same as second column of $TargetSeqPath/Ref.tmp
for e.g.
first record of $REG_InputFileName is
"UPDATE","1010021126","1-01-01","USD"
so first three characters will be 101 now i need to lookup this 101 into $TargetSeqPath/Ref.tmp and there is match ;
001.,ARE
then this whole record "UPDATE","1010021126","1-01-01","USD" should go to a directory named as ARE
i have following code for this :
while read i
do
echo $i > $TargetSeqPath/Ref.tmp
OutDir=`awk -F"," '{print $2}' $TargetSeqPath/Ref.tmp`
awk -F"," 'NR==FNR {col1[substr($1,1,3)]=$2} NR!=FNR { if (col1[substr($2,2,3)]=="") {next} print $0}' $TargetSeqPath/Ref.tmp $REG_InputFileName >>$Target
SeqPath/$OutDir/$OutFile-$mdt.txt
done < $RefInputFileName
this is code is working fine and i am getting everything mentioned above. But the problem is if there is match.
for e.g.
"UPDATE","2620021162","1-01-01","USD"
then this record should go to a directory named as "others"
Can anybody help me how to check this mismatch and send the record to other directory
Thanks