When we are using AWK, $1 is to print first field, $2 is for second field and...so on. I was trying like in a for loop for fist iteration I need first filed to be print and for second iteration second filed to be print.... I tried like below.
Example1:
var="sri|ram|good|boy"
for i in {1..4}{
var1=$($var|awk -F'|' -v x=$i '{print $x}');
}
I am new to AWK, is this possible or is there any other way to work on this, suggest on this.
Example 2:
var2="I dont know awk";
for i in {1..5}{
read inputfiled;
echo "$var2"|awk '{print $inputfiled}' #syntax wrong
}
Here if i give inputfiled value as 1 it should print I, If i give inputfiled value as 3 should print know.
either of the any answer could help me.