Reputation: 12176
I know I can use awk to get a line starting with expression exp
by awk '/^exp/'
. How do I get the n-th word from this line?
Upvotes: 0
Views: 555
Reputation: 195199
give this a try:
awk -v n="$var" '/^exp/{print $n}' file
$var
could be shell variable, the value is the index of your column.
Upvotes: 2
Reputation: 1723
Use {print $n} in the awk statement
echo "abcd bcd cd d" | awk '/^ab/ { print $3}'
This would echo "cd"
Upvotes: 3