Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

hi all To find if field 5 has I use the:

   [[ -z ` echo $LINE  | awk '{print $5}' ` ]]

my question if there is another elegant way to verify if field 5 is zero?

THX Yael

share|improve this question
provide example lines – akira Jun 27 '10 at 9:02
LINE=123 aaa ddd ggg ttt yyy hhh – yael Jun 27 '10 at 10:00
up vote 2 down vote accepted

After length5=$(echo $LINE | awk '{ print length($5)}') the variable $lenght5 will contain the length of field 5;

Note: in your example line, if ttt were empty, yyy would be field 5, so be careful: you can use

awk -F' '

instead of awk to make the space the field delimiter, so that 2 spaces = empty field....

share|improve this answer

This will pass if the 5th field is the string 0 (and won't if it's 00, 0.0, or it's absent etc).


LINE="123 aaa ddd ggg 0 yyy hhh"

if [[ "0" = `echo ${LINE}  | awk '{print $5}'` ]]
   echo "5th field is string '0'"
   echo "5th field isn't string '0'"

Does that do what you want?

It would be useful if you provided more example input.

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.