#!/bin/bash
index=101,102,103,104,105
/bin/echo "$index" | /bin/awk -F\, '{print $2}'
above is my shell script,(this is just a demo It should not be static) when I execute this It returns me value “102” it is right.
#!/bin/bash
index=101,102,103,104,105
for i in 1 2 3 4 5
do
/bin/echo "$index" | /bin/awk -F\, '{print $i}'
done
I want to print all numbers one by one…where I am wrong ?
I have made some changes with “null” saprated values…Now what changes I suppose to make?
to get and increment values of $i ?
output of *some command*
1013
1023
12324
13224
3122
2421
#!/bin/bash
index=*some command*
i=1
for LINE in ${OUTPUT} ; do
ans=$(/bin/echo "$index" | /bin/awk -vRS= -vFS="\n" '{print $i}')
i=`expr $i + 1`
done
Use double quotes so
$igets expanded by the shell. You have to quote the dollar sign, then, to prevent the expansion of$$: