Hello there.
I want some help with awk
I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor
echo "give a choice"
read -a ans
array=${ans[@]}
awk -F: -v k="$array" '{
split(k,l," ")
for(i=1;i<=NF;i++)
{
printf("%s \t",$l)
} printf("\n")
}' /etc/passwd
I get the field numbers from an array and then I split this array in awk.
If I try to print "l[i]" it works but when I try to print it as field number I dont get the correct result.
I want my outpout to be something like this :
for example:
>give a choice
:1 5 3
and then I will like to print the first field in each line then the 5th and then the 3rd
first fifth third
first fifth third
first fifth third
............