Operating System - HP-UX
1834168 Members
2039 Online
110064 Solutions
New Discussion

Re: write if state for file size

 
SOLVED
Go to solution
Ratzie
Super Advisor

write if state for file size

Is there a way to write an if state if file size is greater than 99?

if [ file size > 99 ]
then
blah...
5 REPLIES 5
Pete Randall
Outstanding Contributor
Solution

Re: write if state for file size

How about using awk and ll?

if `ll FILE | awk '{print $5}' -gt "99"`


Pete

Pete
Shannon Petry
Honored Contributor

Re: write if state for file size

Yes, and no.

No meaning that test options will not handle this. I.E.
if [ -x myfile ] ; then
echo "it's executable"
elif [ -w myfile ] ; then
echo "it's writable"
fi
Man test for more information on built in testing.

yes, you can make it work by grabbing the file size.

_size=`ls -l myfile|awk '{print $5}'`
if [ "${_size}" -gt "1" ] ; then
# do something
else
# do something else
fi

Similarly, this would work

if [ `ls -l myfile | awk '{print $5}'` -gt 1 ] ; then
# do something
fi

If you do not like "-gt", then ">" does the same thing.


Regards,
Shannon

Microsoft. When do you want a virus today?
Pete Randall
Outstanding Contributor

Re: write if state for file size

Oops!

if [ `ll FILE | awk '{print $5}'` -gt "99" ]


Pete

Pete
Victor Fridyev
Honored Contributor

Re: write if state for file size

Hi

if [ $(cat $FILE| wc -c ) - gt 99 ] ; then
.......
Entities are not to be multiplied beyond necessity - RTFM
Ratzie
Super Advisor

Re: write if state for file size

Answered works