Link to home
Start Free TrialLog in
Avatar of toooki
toooki

asked on

UNIX shell script parse a line

I have a file in my UNIX server whose content is like this:
#cat myfile.txt
        25
#
OR:
#cat myfile.txt
        0
#

I need to parse the content to find out if the number is > 0. There are leading and trailing spaces in the line myfile.txt .
How could I compare the content... Any suggestion could be very helpful..Below is my code and pseudo code... Thnak you!

##Content of the .sh file:
#!/bin/sh
tmp=/tmp/mail-body1-`date +%F`;
touch $tmp && chmod 600 $tmp;
/bin/cat /usr/mydir/myfile.txt >> $tmp

#Now this is what I want to do:

IF $tmp > 0

THEN
###
/usr/sbin/sendmail -t < $msg;
##

ELSE
##
do nothing
###
SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
toooki

ASKER

Thank you.

I tried:

/bin/cat /usr/mydir/myfile.txt >> $tmp
value=$(cat $tmp)
if [[ $value -lt 0 ]]; then
/usr/sbin/sendmail -t < $SUBJECT
fi

Also tried:
/bin/cat /usr/mydir/myfile.txt >> $tmp
value=$(cat $tmp)
if [[ $value -gt 0 ]]; then
/usr/sbin/sendmail -t < $SUBJECT
fi

It does not go to the sendmail part.
the code alone:
/usr/sbin/sendmail -t < $SUBJECT
The above works.

Thanks.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki

ASKER

Worked thank you!
Glad it worked

would you mind to award points and close the question?