I have an awk
command which runs well on terminal: this awk
command creates different file according to their column header.
awk command:
for((i=2;i<5;i++)); do
awk -v i=$i 'BEGIN{OFS=FS="\t"}NR==1{n=$i}{print $1,$i > n".txt"}' ${Batch}.result.txt
done
the same command when incorporated in a shell script shows error:
Syntax error: Bad for loop variable
It worked the following way. I tried with she-bang as suggested but it repeated the error.
for i in 2 3 4; do awk -v i=$i 'BEGIN{OFS=FS="\t"}NR==1{n=$i}{print $1,$i n".txt"}'
{2..4}
either. He needs to specify the shell properly, as in the other answers. – Barmar Nov 03 '17 at 15:04