0
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
0
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
2
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....
0
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.
provide example lines – akira – 2010-06-27T09:02:41.307
LINE=123 aaa ddd ggg ttt yyy hhh – yael – 2010-06-27T10:00:15.497