1827887 Members
1667 Online
109969 Solutions
New Discussion

Re: script

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

script

Hi,

I have a text file with dat in the following format:

A dog 77
B cat 104
C lion 147
D tiger 63
and so on.....

I want to grep all the lines whose values are more then 100? How can I do it in hpux?

Final result:
B cat 104
C lion 147

Thanks,
Raje.


Everything is possible
6 REPLIES 6
Andreas Voss
Honored Contributor
Solution

Re: script

Hi,

try this:

awk '{if($3 > 100)print $0}' textfile

Regards
Leif Halvarsson_2
Honored Contributor

Re: script

Hi
Or you can use shell script
while read a b c
do
if [ $c -gt 100 ]
then
print a b c
fi
done
Sukant Naik
Trusted Contributor

Re: script

Hi Raje,

This is the way, I tried

while read j
do
number=`echo $j | cut -d" " -f3 `
if test "$number" -gt "100"
then
echo $j
fi
done B cat 104
C lion 147

Regards,
Sukant
Who dares he wins
Leif Halvarsson_2
Honored Contributor

Re: script

Sorry, I forgot the "$"
of course:

print $a $b $c
Robin Wakefield
Honored Contributor

Re: script

Hi Raje,

awk:
awk '$3>100{print}' file

perl:
perl -nae '{print if ($F[2]>100)}' file

Rgds, Robin

H.Merijn Brand (procura
Honored Contributor

Re: script

Should

A dog567b 2

be selected?

if yes:

# perl -ne '/\d+/&&$&>100&&print' infile
B cat 104
C lion 147

if no (safer)

# perl -ne '/\b\d+\s*$/&&$&>100&&print' infile
B cat 104
C lion 147
Enjoy, Have FUN! H.Merijn