1

Suppose which I have this table:

one two three four
two three four five
three four five six
four five six seven
five six seven eight

so I wrote awk -v word=two '$0 ~ "[^[:alpha:]]" word "[^[:alpha:]]"'from this link to access all lines which have two. and the result is whole of line:

one two three four
two three four five

If I want to find just $3. what I should add for that command?

If I want to search on the internet to find the answer. what do I should search? Or better to say this easy:( question refer to which topic of AWK?

7
  • Why have you added the link? any why so hidden, make it more easily visible. Jul 10, 2014 at 5:57
  • @RegisteredUser I did an update Jul 10, 2014 at 6:01
  • I think the command is wrong. Jul 10, 2014 at 6:05
  • no I change ABC to two.I wrote wrong but I updated Jul 10, 2014 at 6:06
  • How are you using the command, by piping it to cat or something OR by providing file on command line OR something else? can you give the whole command? Jul 10, 2014 at 6:08

1 Answer 1

2

You have to use {print$n} to print the nth word. So in your case it would be {print$3}

The Final command becomes,

awk -v word=two '$0 ~ "[^[:alpha:]]" word "[^[:alpha:]]" {print$3}'

which will give output

three
four

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .