i want to compare records in file a to file b such that when the name tom is found in file b column 1 and has either newyork or ohio or oregon IN Column 3 display as
tom|NOO
else display
sam|YES.
so the output of file a after comparison should be
tom | NOO
lasole|YES
jon|YES
gille|YES
sam|YES
since tom has either newyork or ohio or oregon in column3 of file b
#!/bin/ksh
for ref in `cat filea`
do
cities=`grep "^$ref fileb"|cut -f3 -d"|"|tr "," " "`
match="NOO"
for city in $cities
do
if [ "$city" = "newyork" -o "$city" = "ohio" -o "$city" = "oregon" ]
then
match="YES"
fi
done
echo "$ref|$match"
done
I hope that this helps, but your desired output is a little inconcistent, so I've had to guess. have a play and let us all know how you get on or if you need more help.
Many thanks Scott. I am a fool in my coding.:rolleyes: I read the text saying column 3 and just coded it straight. :o
So, dealerso, now with proper testing, I found that my logic was in reverse too.
Amended & testing code appended:-
for ref in `cat filea`
do
cities=`grep "^$ref" fileb|cut -f4 -d"|"|tr "," " "`
match="YES"
for city in $cities
do
if [ "$city" = "newyork" -o "$city" = "ohio" -o "$city" = "oregon" ]
then
match="NOO"
fi
done
echo "$ref|$match"
done
From the input given, I get the output:-
tom|NOO
lasole|YES
jon|YES
gille|YES
sam|YES
Not quite what is shown, but that would be more to code, unless you really want the spaces around the pipe mark for record tom.
Does that fix things up? Let us all know if this is the answer or if I have missed something.