Line/Variable Editing for Awk sed Cut

Hello,
i have a file, i open the file and read the line, i want to get the first item in the csv file and also teh third+6 item and wirte it to a new csv file. only problem is that using echo it takes TOO LONG:

please help a newbie. below is my code:

WorkingDir=$1
FileName=`cut -d ',' -f 2-2 $WorkingDir/info.csv | sed q`

while read line
do
        InstrName=`echo $line | cut -d ',' -f 1-1`
        VarC=`echo $line | cut -d ',' -f 3-3`
        VarD=`echo $line | cut -d ',' -f 4-4`
        VarF=`echo $line | cut -d ',' -f 6-6`

        if [ $VarC=$VarD ];
        then
                Total=$(($VarC + $VarF))
                echo $InstrName "," $Total >> $FileName
        else
                echo "ERROR IN SYSTEM!! SEND EMAIL"
        fi
done < $WorkingDir/solution.csv

Try this loop instead that reads the values directly into the variables:

while IFS=, read InstrName VarB VarC VarD VarE VarF x
do
  if [ "$VarC" = "$VarD" ]; then
    Total=$((VarC + VarF))
    echo "$InstrName , $Total"
  else
    echo "ERROR IN SYSTEM!! SEND EMAIL"
  fi
done < "$WorkingDir/solution.csv" > "$FileName"
1 Like

Excellent it worked in record time!! :slight_smile: Thank you.