1748204 Members
3453 Online
108759 Solutions
New Discussion юеВ

Re: grep command

 
SOLVED
Go to solution
Francisco J. Soler
Honored Contributor

Re: grep command

Hi again,

I made a mistake in the command, the correct one is:

grep $ADRESSIP file > /dev/null && echo $ADRESSIP.

Sorry
Frank.
Linux?. Yes, of course.
Bharat Katkar
Honored Contributor

Re: grep command

Frank,
What about this one:

# cat > xyz
one
two three
four
five
#
# VAR=one
# cat xyz | grep "$VAR"
one
#

Remember i am using default POSIX shell of HPUX.
This should work with KSH also.

Regards,

You need to know a lot to actually know how little you know
harry d brown jr
Honored Contributor

Re: grep command

IN RESPONSE TO YOUR: on my HPUX B.11.00 "grep -x and grep -w" not working ! Problem with patches ?


YES, you need to PATCH your system, as "grep -w" and "grep -x" should exist and work.

live free or die
harry
Live Free or Die
Bharat Katkar
Honored Contributor

Re: grep command

Sorry,
Earlier one is having bug in that. Try this one. it is bit lengthy, hope you don't mind.

create one script called "myscr" and you have file called "xyz" then:
# cat myscript

#!/usr/bin/ksh
list=`cat xyz`
myfunct()
{
VAR11=$#
while true
do
if [ VAR11 -gt 0 ]
then
echo $1
shift
let VAR11=$VAR11-1
else
exit
fi
done
}
myfunct $list

----- end of script ----------

#chmod +x myscript
#./myscript | grep "$VAR"

I have tested this one and works fine.

Regards,
You need to know a lot to actually know how little you know
Bharat Katkar
Honored Contributor
Solution

Re: grep command

Now look at this one, more user friendly.
Again don't mind the lenght, it's once for all.

#!/usr/bin/ksh
echo " Enter values to be searched in file : "
read VAR1
echo "\n Enter file name in which the above value to be searched : "
read VAR2
list=`cat $VAR2`
myfunct()
{
VAR11=$#
while true
do
if [ VAR11 -gt 0 ]
then
echo $1
shift
let VAR11=$VAR11-1
else
exit
fi
done
}
myfunct $list | grep "$VAR1"


Let me know if that helped.
Regards,
You need to know a lot to actually know how little you know
KapilRaj
Honored Contributor

Re: grep command

Hey,

I get this problem when I use -w. Can u download a gnu version of grep and try grep -w ?.

Regds,

Kaps
Nothing is impossible
Abdul Rahiman
Esteemed Contributor

Re: grep command

I think HP-UX grep don't have the -w option. Someone mentioned about a patch ??

We resolved this be downloading the gnu grep (ggrep) from www.gnu.org. ggrep has much more than -w to offer in my opinion.
No unix, no fun
Mark Grant
Honored Contributor

Re: grep command

Does this work

perl -ne '/\b156.152.45.5\b/ && print' datafile
Never preceed any demonstration with anything more predictive than "watch this"
Mark Grant
Honored Contributor

Re: grep command

Or, if you want it to take the variable

export ADRESSIP="156.152.45.5"
perl -ne '/\b$ENV{ADRESSIP}\b/ && print'
Never preceed any demonstration with anything more predictive than "watch this"
KapilRaj
Honored Contributor

Re: grep command

i can confirm "-w" doesn't work in AIX as well

Kaps
Nothing is impossible