bash shellscript for loop two variables with input from two files
I have a file1:
I need to compare usedmem(column5)from file2 with free memory(column4) from file1. If free memory(column4) from file1 is greater than usedmem(column5)from file2. The output should be VM(column2) from file2 can be relocated to storage(column1) in file1. Files are sorted in descending order
storage,totalmem,usedmem,freemem
0843,524230,241374,282856
0867,524230,253339,270891
0842,524230,291427,232803
0868,262086,48660,213426
0849,524230,335445,188785
0844,524230,335446,188784
0860,524230,354981,169249
0855,524230,354984,169246
0862,524230,354985,169245
0853,524230,354986,169244
0850,524230,411733,112497
0857,524230,411734,112496
0841,524230,411734,112496
0839,524230,411735,112495
0848,524230,411736,112494
0851,524230,411737,112493
file2
storage, vm ,rack,usedcpu,usedmem,type
0839,x0aaa05,US1 DA12,4,78851,FA
0839,x0aaa01,US1 DA12,5,10243,OIM
0839,x0aaa03,US1 DA12,6,4099,OHS
Desired output -
significant memory does not exist in 0843 to relocate x0aaa06
x0aaa05 can be relocated to 0867
x0aaa01 can be relocated to 0842
x0aaa03 can be relocated to 0868
I have been trying to use for loop to pass something like
for i in `cat file2|wc -l`
do
j=`cat file1|cut -d, -f4`
m=`cat file2|cut -d, -f5`
file1_dom=`cat file1|cut -d, -f1`
file2_vm=`cat file2|cut -d, -f2`
if [[ `${j} -gt ${m}` ]]
then
echo ${file2_vm} can be reclocated to ${file1_dom}
fi
done
output - erroring out
-bash: 282856: command not found
example 2-
set -- $( cat file1|cut -d, -f4 )
for i in `cat file2|cut -d, -f5`
do
if [[ $1 -gt $i ]]
then
echo $1 can be relocated to $i
fi
done
Output -
282856 can be relocated to 78851
282856 can be relocated to 10243
282856 can be relocated to 4099