Unix Technical Forum

How to use grep function to search exact word in HP UNIX 11.0

This is a discussion on How to use grep function to search exact word in HP UNIX 11.0 within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> Dear all I tried to use grep function in HP UNIX 11.0 for matching exact word in a reference ...


Go Back   Unix Technical Forum > Unix Operating Systems > HP-UX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-17-2008, 06:33 AM
bonnie.tangyn@gmail.com
 
Posts: n/a
Default How to use grep function to search exact word in HP UNIX 11.0

Dear all

I tried to use grep function in HP UNIX 11.0 for matching exact word in
a reference file. It not only returns exact matched word, but also
returns similar matched word.

My reference file:
abc20060812 code01
abc_def20060812 code02
xyz_qpr_sty20060812 code03

I tried:
for f in *.txt
{
key=${f%%2*}
mapped_code='grep $key $referencefile | cut -f2 -d" "'
printf "%s%s\n" $mapped_code $(date +%y%m%d)
....
}
done

I want to output:
code01060812 (in file 1 header)
code02060812 (in file 2 header)

But, it output:
code01code02060812 (in file1and file2)

I also tried:
mapped_code='grep -w $key $referencefile | cut -f2 -d" "'
or
mapped_code='grep \<$key\> $referencefile | cut -f2 -d" "'

However, it generates error and cannot match the exact word
respectively. I read other news in google groups. I found grep -w and
grep \<$key\> does not work in HP UNIX.

Could you give me some suggestions?

Cheers
Bon

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-17-2008, 06:33 AM
OldSchool
 
Posts: n/a
Default Re: How to use grep function to search exact word in HP UNIX 11.0


bonnie.tangyn@gmail.com wrote:
>
> Could you give me some suggestions?
>
> Cheers
> Bon


You didn't give an example of the "Key" you were searching for,
however:

having located the lines that contain the pattern, could you not "test"
the value of the key against the located field? ie.

if [ "$key" = "$found" ]
then
echo "same"
else
echo "not the same"
fi


also, you should be able to download the gnu version of grep from
either the hp porting center or rtr.com. just don't put it in place of
the HPUX version, as I've seen it cause problems w/ SAM

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com