AMB
AMB

Reputation: 55

Calling AWK and Shell Scripting

I'm having a problem with a Shell Script.

In a nutshell I want to print the "$2" column of the file "$1" in my script "showColumn"

So, what I've tried:

#!/bin/bash
awk '{print $($2)}' $1
exit 0

Ok, I know that $($2) is totally incorrect, but you can see what I'm trying to do.

So what I want when I write "./showColumn file.txt 2" is printing the second column of file.txt but I don't know how to solve that.

Upvotes: 1

Views: 123

Answers (1)

Tripp Kinetics
Tripp Kinetics

Reputation: 5449

Try:

#!/bin/bash
awk -v column="$2" '{print $column}' "$1"
exit 0

Upvotes: 2

Related Questions