Hi,
im having problem creating a loop using my code: aside from the fact that the 1st variable (VAR) does not increment, it loops more than the expected output.
for sample purposes, test csv contains 3 lines.
#get number of lines in the file
lines=$( wc -l < test.csv )
VAR=1
VAR2=1
while [ $VAR -le $lines+1 ]
do
while [ $VAR2 -le $lines+1 ]
do
sed "s/,,/,one"$VAR"too"$VAR2",/" test.csv > test1.csv
VAR2=$(( $VAR2 + 1 ))
done
VAR=$(( $VAR + 1 ))
done
Output of the code is like this, this is caused by the sed command, its like the script executes first the sed command then the loop:
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f
a,b,c,d,e,one1too4,f
But the output should be:
a,b,c,d,e,one1too1,f
a,b,c,d,e,one1too2,f
a,b,c,d,e,one1too3,f
a,b,c,d,e,one1too4,f
i hope i explained and posted this question appropriately...
Hope someone could help..really appreaciate it.. thanks!