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
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
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....
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).
#!/bin/bash
LINE="123 aaa ddd ggg 0 yyy hhh"
if [[ "0" = `echo ${LINE} | awk '{print $5}'` ]]
then
echo "5th field is string '0'"
else
echo "5th field isn't string '0'"
fi
Does that do what you want?
It would be useful if you provided more example input.