Thursday, December 6, 2007

Search for skus


#!/bin/ksh

BigFile='/home/usrbinsed/Desktop/tmp/2008margins.csv'
SmallFile='/home/usrbinsed/Desktop/tmp/salesbypart07.csv'

BigFileCount=$(cat $BigFile | wc -l)
Counter='1'
MatchCounter='0'

until [ $Counter -gt $BigFileCount ]
do
CurrentRecord=$(cat "$BigFile" | awk 'FNR == '$Counter' {print}')
CurrentSKU=$(echo $CurrentRecord | awk -F"," '{print $1}')
SmallFileMatch=$(cat $SmallFile | awk -F"," '{print $1}' | grep -xn $CurrentSKU)
if [ -n "$SmallFileMatch" ]
then
MatchRecord=$(cat $SmallFile | awk 'FNR == '$(echo $SmallFileMatch | awk -F":" '{print $1}')' {print}')
echo "$CurrentRecord, $MatchRecord"
((MatchCounter = MatchCounter + 1))
else
echo "$CurrentRecord"
fi
((Counter = Counter + 1))
done
echo "Total Matches = $MatchCounter"

No comments: