Hello!
I've got a loop in which I am processing a list of values gotten through a file with read command.
It seems that instead of processing the lines (values) one by one, I process them all together.
the input file is:
20
20
20
80
70
70
20
The code is:
#!/bin/sh
while read -r Line
do
STR5="$(awk 'BEGIN {FS = ","} ; {print $1}')"
if [ "$STR5" = "20" ]; then
echo "CHOICE A" >> SEN5$1.txt
elif [ "$STR5" = "70" ]; then
echo "CHOICE B" >> SEN5$1.txt
elif [ "$STR5" = "80" ]; then
echo "CHOICE C" >> SEN5$1.txt
else
echo "$STR5" >> SEN5$1.txt
fi
echo "$STR5" >> SEN5$1.txt
done < input.txt
and produces the same output as the input file, meaning that the last 'else' statement is validated each time. By testing I have seen that it takes the whole file (all lines) in each iteration.
I have also tested this code:
while read -r Line
do
awk 'BEGIN {FS = ","} ; { if ($1 = 20) print "CHOICE A"; else if ($1 = 70) print "CHOICE B"; else if ($1 = 80) print "CHOICE C" ; else print $1}' >> SEN5$1.txt
done < input.txt
which returns
CHOICE A
CHOICE A
CHOICE A
CHOICE A
CHOICE A
CHOICE A
CHOICE A
which propably is due to checking with the 1st value each time.
Any ideas?
