System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

confirmation of fgrep or grep -f bug sought - diff OK

Michael Steele_2
Honored Contributor

confirmation of fgrep or grep -f bug sought - diff OK

Hi Folks: Anyone else notice the failure of grep -f or fgrep in HP-UX? The return values don't change when tested against like or unlike files, i.e $? always equals 0 or 1 when they should report 0 for equalities and 1 for inequalities. Because of this I've had to implement the diff command.

The HP patch database also reports an enormous number of patches associated to grep. What's up with this?

I assume this has been reported as a bug to HP but can one of you guys confirm? I'm using 11.00. Is there a patch remedy?
Support Fatherhood - Stop Family Law
11 REPLIES
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

M,

Can you post the command you were using to test this?

because I get the right results.


# cat hits_data2
Xbcdefg
hijklmn
# cat hits_data1
abcdefg
hijklmn
# cat hits_pat
abcdefg
# cat hits
#!/usr/bin/ksh
grep -f /tmp/hits_pat $1
echo $?
# ./hits /tmp/hits_data1
abcdefg
0
# ./hits /tmp/hits_data2
1
#


live free or die
harry

Live Free or Die
Michael Steele_2
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

# cat 1

Owner: SYSTEM
Name: Permissions:
-------------------------------------------------------------------------------
*Administrators FullControl(All)(All)
*CREATOR OWNER FullControl(All)(All)
*NUICORP\UBS-OAS Admin FullControl(All)(All)
*NUICORP\UBS-OAS Applications Change(RWXD)(RWXD)
*NUICORP\UBS-OAS Mapping Change(RWXD)(RWXD)
*NUICORP\UBS-OAS Programming Change(RWXD)(RWXD)
*SYSTEM SpecialAccess(All)*(NotSpecified)

The command completed successfully.

# cat 2

Owner: SYSTEM
Name: Permissions:
-------------------------------------------------------------------------------
*Administrators FullControl(All)
*NUICORP\UBS-OAS Admin FullControl(All)
*NUICORP\UBS-OAS Applications Change(RWXD)
*NUICORP\UBS-OAS Mapping Change(RWXD)
*NUICORP\UBS-OAS Programming Change(RWXD)
*SYSTEM FullControl(All)

The command completed successfully.
[nuiprd3]:/home/mfs/ACL_PERMS/Database # grep -f 1 1

# grep -f 1 1

Name: Permissions:
-------------------------------------------------------------------------------
*Administrators FullControl(All)(All)
*CREATOR OWNER FullControl(All)(All)
*NUICORP\UBS-OAS Admin FullControl(All)(All)
*NUICORP\UBS-OAS Applications Change(RWXD)(RWXD)
*NUICORP\UBS-OAS Mapping Change(RWXD)(RWXD)
*NUICORP\UBS-OAS Programming Change(RWXD)(RWXD)
*SYSTEM SpecialAccess(All)*(NotSpecified)

The command completed successfully.

# echo $?

0

# grep -f 1 2^M

Owner: SYSTEM

Name: Permissions:
-------------------------------------------------------------------------------
*Administrators FullControl(All)
*NUICORP\UBS-OAS Admin FullControl(All)
*NUICORP\UBS-OAS Applications Change(RWXD)
*NUICORP\UBS-OAS Mapping Change(RWXD)
*NUICORP\UBS-OAS Programming Change(RWXD)
*SYSTEM FullControl(All)

The command completed successfully.

echo $?^M

0

# fgrep 1 1^M

# echo $?^M

1

# fgrep 1 2^M

# echo $?

1

# diff 1 1^M

# echo $?^M

0

# diff 1 2^M

4,10c4,9
< *Administrators FullControl(All)(All)
< *CREATOR OWNER FullControl(All)(All)
< *NUICORP\UBS-OAS Admin FullControl(All)(All)
< *NUICORP\UBS-OAS Applications Change(RWXD)(RWXD)
< *NUICORP\UBS-OAS Mapping Change(RWXD)(RWXD)
< *NUICORP\UBS-OAS Programming Change(RWXD)(RWXD)
< *SYSTEM SpecialAccess(All)*(NotSpecified)
---
> *Administrators FullControl(All)
> *NUICORP\UBS-OAS Admin FullControl(All)
> *NUICORP\UBS-OAS Applications Change(RWXD)
> *NUICORP\UBS-OAS Mapping Change(RWXD)
> *NUICORP\UBS-OAS Programming Change(RWXD)
> *SYSTEM FullControl(All)

# echo $?^M

1
Support Fatherhood - Stop Family Law
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

File 1 and File 2 have some lines that are identical, therefore

grep -f 1 2

will result in a 0

fgrep is obsolete, and you aren't using it right, because this:

fgrep 1 1

is comparing the string "1" to the File named "1", and because there are NO "1"'s in the File named "1", then the result is "1".

fgrep 1 2

Same here too, because there are NO 1's in the File named "2".




TRY this:

# fgrep OWNER 1
*CREATOR OWNER FullControl(All)(All)
# echo $?
0
# fgrep UGLYSTICK 1
# echo $?
1
#



Because there is the pattern "OWNER" in the File named "1", then this command is successful!


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

M,

fgrep has the format of

fgrep [-cefilnsvx] [strings] [file ...]


to use a FILE of STRINGS, then use:

fgrep -f FILEofPATTERNS FILE2SEARCH

live free or die
harry
Live Free or Die
Michael Steele_2
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

Ok on fgrep -f.

Not OK with grep -f which should produce the same result as fgrep -f.

Right?
Support Fatherhood - Stop Family Law
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

M,

Wrong option, to get "grep" to act like "fgrep" use the "-F" option, not the "-f" option:

# grep -f OWNER 1
grep: can't open OWNER
# grep -F OWNER 1
*CREATOR OWNER FullControl(All)(All)
#


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

Also, please read this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html

live free or die
harry
Live Free or Die
Michael Steele_2
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

Please be more specific
Support Fatherhood - Stop Family Law
harry d brown jr
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

http://66.216.15.50/ITRCForumsEtiquette/after.html

live free or die
harry
Live Free or Die
Michael Steele_2
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

Hmmmmmm, 15 points were assigned to other forum members. (?????????????)
Support Fatherhood - Stop Family Law
Michael Steele_2
Honored Contributor

Re: confirmation of fgrep or grep -f bug sought - diff OK

.
Support Fatherhood - Stop Family Law