I have an issue with the if statement, basically I want to write the values of $tag9700
and $tag9701
to the 9700l.log
and 9701l.log
respectively if they exist. If they don't then write 9700=,
to 9700l.log and 9701=,
to 9700l.log
.
tag9700=`egrep -Eo '9700=[0-2]{0,9}' $filename-PDK-AP-LXFXMR-01*.log`
if [ $tag9700 -eq 0 ]
then
echo $tag9700 >> /home/user/9700l.log
else
echo '9700=,' >> /home/user/9700l.log
fi
tag9701=`egrep -Eo '9701=[A-Z]{0,9}' $filename-PDK-AP-LXFXMR-01*.log`
if [ $tag9701 -eq 0 ]
then
echo $tag9701 >> /home/user/9701l.log
else
echo '9701=,' >> /home/user/9701l.log
fi
The outcome is that 9700l.log
file should look like:
9700=1
9700=0
9700=,(only if it isn't a value grepped in the intial $tag9700)
The same scenario applies to $tag9701
.
if [ "$tag9700" -eq 0 ]
, and what you probably want isif [ -n "$tag9700" ]
anyway. I don't think that grep will ever print a zero. – ilkkachu Mar 15 '17 at 10:27