In: Computer Science
this lab, you will write a shell script, called compare_cols.sh. This program should
one two three,four five,six seven,eight,nine six ten,eleven
Bashscript
Answer) # indicates the comment
echo "Enter the file name"
#read the file from standard input
read fn
#take a counter for line count
c=0
#start the while loop to read every line from the file
while read -r l1
do
#extract the first word of column3 from the line
col3=`echo $l1|cut -d "," -f 3|cut -d " " -f 1`
#extract column5 from the line
col5=`echo $l1|cut -d "," -f 5`
#search col3 from col5
echo $col5|grep $col3 >/dev/null
#check if found then increase c by 1
if test $? -eq 0
then
c=`expr $c + 1`
fi
#loop end and suppy the file name
done < $fn
#display the output of the count
echo $c
Screenshot