Raja G
Raja G

Reputation: 6633

Awk script not listing specific column

Using awk I have written this script but it's not working properly. Even I expected just only specific column it's displaying me total column of information.

n=0
echo  "Enter which column you want: "
read  n
awk '{print $($n)}' out.txt

I would like to have only specific column for the value of n.

Thank you

Upvotes: 2

Views: 79

Answers (1)

Jens
Jens

Reputation: 72639

There is no parameter substitution within single quotes. Use

awk '{print $'$n'}' out.txt

or use an awk variable as in

awk -v n="$n" '{print $n}' out.txt

Upvotes: 4

Related Questions