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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| 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 |