BASH - variable as variable
by carlolab from LinuxQuestions.org on (#520ZF)
Hi,
I have a "fileX" test file with a content like this:
a b c d e f
I need to make a for cicle to print column 2 to 6
for col in {2..6}
do
cat fileX | awk '{ print $$col }'
done
The problem is to pass variable $col as variable in print function of awk.
The part '{ print $$col }' shold be read as '{ print $2 }' then '{ print $3 }' etc.etc.
Can someone help me?
Thank You
Carlo


I have a "fileX" test file with a content like this:
a b c d e f
I need to make a for cicle to print column 2 to 6
for col in {2..6}
do
cat fileX | awk '{ print $$col }'
done
The problem is to pass variable $col as variable in print function of awk.
The part '{ print $$col }' shold be read as '{ print $2 }' then '{ print $3 }' etc.etc.
Can someone help me?
Thank You
Carlo