I want to make a simple gawk
script to extract the nth column of some file. The name of the file and the value for n I want to be entered at the command line. This script I make executable with chmod +x
.
Thus to extract the third column from the file foo I would enter:
awkextract foo 3
My attempt at the script awkextract
is:
#!/opt/local/bin/gawk -v k=$2 -f
{print $k}
But the nonsense results show that this isn't working. How do I fix it?
PS. I know I can do this via cut
command, I'm just experimenting...