Groups > SUSE Linux > openSUSE applications > Re: help with grep




help with grep

help with grep
Wed, 20 Feb 2008 00:36:01 GMT
I have a file with the following line

NumberofSchduledJobs         66

The number at the end of the line will always be changing

I need to get that value and test it to see if is greater than 100 with
an if the will do something else.

if x > 100 then

bla bla

end if


-- 
rstout
------------------------------------------------------------------------
rstout's Profile: http://forums.novell.com/member.php?userid=4504
View this thread: http://forums.novell.com/showthread.php?t=312465
Post Reply
Re: help with grep
Wed, 20 Feb 2008 02:58:39 GMT
rstout wrote:

> 
> I have a file with the following line
> 
> NumberofSchduledJobs         66
> 
> The number at the end of the line will always be changing
> 
> I need to get that value and test it to see if is greater than 100 with
> an if the will do something else.
> 
> if x > 100 then
> 
> bla bla
> 
> end if
> 
> 

Try this bash script

#!/bin/bash

if [ $(grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2 }')
> 100 ];
then
  echo "greater than 100"
else
  echo "less than 100"
fi


Jim


-- 
Pye, James Pye, chmod 007, The Ultimate Open Source

You know it's going to be a bad day when you hear
Post Reply
Re: help with grep
Wed, 20 Feb 2008 04:46:01 GMT
if I run the command 
grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2 }'
from the command prompt I get 66 but in the script I always get greater
than
To test I even changed the > to a < and it still returns greater than
100
syntax problem?


-- 
rstout
------------------------------------------------------------------------
rstout's Profile: http://forums.novell.com/member.php?userid=4504
View this thread: http://forums.novell.com/showthread.php?t=312465
Post Reply
Re: help with grep
Wed, 20 Feb 2008 05:26:01 GMT
got it 
it should be 
if [ $(grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2 }')
-gt
100 ];
not
if [ $(grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2 }')
>
100 ];
string interger thing

Thanks it really helped me to get going in the right direction.


-- 
rstout
------------------------------------------------------------------------
rstout's Profile: http://forums.novell.com/member.php?userid=4504
View this thread: http://forums.novell.com/showthread.php?t=312465
Post Reply
Re: help with grep
Wed, 20 Feb 2008 08:09:37 GMT
rstout wrote:

> 
> got it
> it should be
> if [ $(grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2
}') -gt
> 100 ];
> not
> if [ $(grep "NumberOfScheduledJobs" file.txt | gawk '{ print $2
}') >
> 100 ];
> string interger thing
> 
> Thanks it really helped me to get going in the right direction.
> 
> 

No probs, weird when I tested it on my system I used -gt first and got an
error but it worked with >  :-(

Note that due to word wrapping the word "then" should have been on the
same
line as the "if". The semi colon is the statement separator allowing
multiple commands on one line.

Jim

-- 
Pye, James Pye, chmod 007, The Ultimate Open Source

You know it's going to be a bad day when you hear
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact