I am using awk in shell script and it is working as expected.
awk -F'^' 'BEGIN {OFS="^"} {print $1,$2,$3,$4,$5}'
When I need to change the number of columns, I simply change the print statement by adding $6,$7,$8
Is there a way to declare it in a variable and use that variable in awk?
columns=8
awk -F'^' 'BEGIN {OFS="^"} {print $1..$columns}'
You could always use a
for-loopusing
printfand theprintafter the loop will give you the linefeed at the end of the line.