Comparing one file’s 3rd column to other file’s column and print – Linux/Unix

This script is created for my brother as he wanted to print the only values which are different from each other in both files but only in 3rd Column.
In this, the first column contains a unique id.

#!/bin/bash
awk -F "," '{print $1}' yash.csv > yashids.csv
for n in `cat yashids.csv`
do
ID=`grep $n net.csv | awk -F "," '{print $3}'`
ID2=`grep $n yash.csv | awk -F "," '{print $3}'`
if [ "$ID" != "$ID2" ]
then
grep $n net.csv yash.csv
fi
done > main-data

cat main-data | sed 's/ ,/,/g'|sed 's/ //g' > main-data2
while read i ; do

comname=`echo "$i" |awk -F "," '{print $2}'`

amount1=`grep -i $comname main-data2|head -n 1|awk -F "," '{print $3}'`
amount2=`grep -i $comname main-data2|tail -n 1|awk -F "," '{print $3}'`
amountdiff=`expr "$amount1" - "$amount2"`

if [ "$amountdiff" -ge 51 ]; then

echo "$i"
fi
done < ./main-data2

 

 

 

Tags:-
Gagandeep Gagan Gagandeep920d

Leave a Reply