Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First I aplogize for this idiot question .

I want to print a field if he is equals to a value .

The problem is that I'm using a non default field sperator and I didn't understand how to make it work .

 awk '{FS = "/" ; if($3=="value" print $3 }'


share|improve this question
To assign an awk "special" variable like FS, either use a command line option like @Thor demonstrated, or use the BEGIN block. The way you've shown in the question means you reassign it for every line of the file. Also, you're missing the close-parentheses for your if condition. – glenn jackman Aug 4 '12 at 22:10
up vote 2 down vote accepted

The more awkish way is like this:

awk -F/ '$3 == "value" { print $3 }'


  • -F specifies the field separator
  • Each block is executed based on the preceding condition, if non is given it is always true, the condition here is $3 == "value".
  • Regular expressions can be used instead if == is replaced with ~.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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