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?

  • Why have you added the link? any why so hidden, make it more easily visible. – Registered User Jul 10 '14 at 5:57
  • @RegisteredUser I did an update – Mohammad Reza Rezwani Jul 10 '14 at 6:01
  • I think the command is wrong. – Registered User Jul 10 '14 at 6:05
  • no I change ABC to two.I wrote wrong but I updated – Mohammad Reza Rezwani Jul 10 '14 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? – Registered User Jul 10 '14 at 6:08

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.