Hi all,
Am new to scripting. So i just need your ideas to help me out. Here goes my requirement.
I have two csv files
1.csv 2.csv
abc,1.24 abc,1
def,2.13 def,1
I need to compare the first column of 1.csv with 2.csv and if matches then need to compare the second coulmnof 1.csv value with 2.csv . if it is more than the 2.csv value then print 1.csv values and second coulmn value of 2.csv and like it goes..And remember the second column of 1.csv is a float value;
the ouput should be in 3.csv
def,2.13,1
my code is goes as folows:
1st way :
for line in `cat 1.csv`
do
samp1=`echo $line|cut -d\'' -f1`;
samp2=`echo $line|cut -d\'' -f2`;
for line in `cat 2.csv`
do
samp3=`echo $line|cut -d\'' -f1`;
samp4=`echo $line|cut -d\'' -f2`;
if [ $samp1 -eq $samp3 ]
then
if [ $samp2 > $samp4 ]
then
print "$samp1",""$samp2"",""$samp4" >> 3.csv;
break;
fi
fi
done
done
--------------------------------
2nd way
Using Awk i tried :
awk -F"," 'BEGIN { {samp1=$1 ; samp2=$2} {awk 'BEGIN {FS = ","} NR == 1 {samp3=$1 ; samp4=$2} \
{if [ $samp1 -eq $samp3 ]
then
if [ $samp2 -gt $samp4 ]
then
print "$samp1",""$samp2"",""$samp3" >> 3.csv
break
fi
fi}}}'1.csv}'2.csv
Using awk in awk...am not sure..:rolleyes: can anybody help on these two ways...am really worried about this since yesterday...
ManyThanks,
Chinna..