I'm currently writing a Linux script using awk to split a given txt file into several small files by columns. My code is as follows
#!/bin/bash
postfix=".txt"
i=0
while [ i -lt 60]
do
colone=`expr $i + 1`
coltwo=`expr $i + 2`
colthree=`expr $i + 3`
colfour=`expr $i + 4`
colfive=`expr $i + 5`
colsix=`expr $i + 6`
filename="$i$postfix"
command="awk '{print $"$colone",$"$coltwo",$"$colthree",$"$colfour",$"$colfive",$"$colsix"}' $1 > $filename"
eval $command
i=`expr $i + 6`
done
I got the error which says
awk: {print mydata.txt,,,,5,6}
awk: ^ syntax error
Is there any way that I can solve this problem?