command line arg issue with awk

Hi friends,

I am trying to pass input from command line and trying to print that column values. (FYI: I am using ksh) My code goes like this...

#!/bin/sh
column=$1
awk '{print $'$column'}'

I execute using command like this --> ls -l | file_name parameter

Hope I am clear with my problem. The error I am getting is something like this,
Syntax Error The source line is 3.
The error context is
awk >>> ' <<<
awk: 0602-500 Quitting The source line is 3.

I tried even removing quotes, but in vain. please help me.
Thanks in advance,
Divya

#!/bin/sh
column=$1
awk -v x=$column '{print $x}'

Hope this works

Thanks a lot buddy, it works :slight_smile: :slight_smile: :slight_smile: