[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::digital_unix

Title:DIGITAL UNIX(FORMERLY KNOWN AS DEC OSF/1)
Notice:Welcome to the Digital UNIX Conference
Moderator:SMURF::DENHAM
Created:Thu Mar 16 1995
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:10068
Total number of notes:35879

9918.0. "/usr/bin/grep and /usr/ucb/grep behave differently to /sbin/grep" by 16.194.80.9::COFFEYJ (La Feline Flooz - a unix cat) Thu May 22 1997 07:55


First of the customer and I both know that results of grep 
on non-text files are unreliable. 

However on this one test file he has on v3.2g all three 
variants of grep produce the same results. 

What is causing a little confusion is that on v4.0b 
on this one file although /sbin/grep finds the 
text string being searched for, and strings piped to 
either other grep also suceeds /usr/ucb/grep and  
/usr/bin/grep both fail to find anything. 

What we're after is some kind of hint of an explaination 
as to why this might be happening. 

Thanks if you can help...

Jo Coffey
unix support
UK CSC
T.RTitleUserPersonal
Name
DateLines
9918.1grepSIOG::BR_MURPHYThu May 22 1997 11:2923
    Could you clarify what command sequence you're running.
    
    grep <search string> <binary file>
    
    	       ANS/OR
    
    /usr/bin/strings <binary file> | grep <search string>
    
    For it's worth /usr/bin/grep & /usr/ucb/grep are the same file /usr/ucb
    is a symbolic link to /usr/bin.
    
    strings <pattern> will search the initialised data space
    strings -a <pattern> will search the whole object file.
    
    You should also note the following comment in the man pages for grep
    
    [Digital]  Running grep on a non-text file (for example, an .o file)
    pro- duces unpredictable results and is discouraged.
    
    
    Brendan
    
    
9918.2finder.uvo.dec.com::COFFEYJLa Feline Flooz - a unix catThu May 22 1997 12:5274
.1 >   You should also note the following comment in the man pages for grep
.1 >  [Digital]  Running grep on a non-text file (for example, an .o file)
.1 >   pro- duces unpredictable results and is discouraged.
 
.0>First off, the customer and I both know that results of grep 
.0>on non-text files are unreliable. 

It's ok, both I and the customer know this, that's why I made it the 
first thing I said, should have known better and mentioned it at the 
end too  :-) 

This query is as much for my sake to help me understand what 
differences it makes to grep having the non-text file and why 
one variant might behave differently to another. 

The customer has already been told not to expect it to work. 



Anyway back to the technical incantations....
the actual command being used are:

/usr/bin/grep dbdev2 aaaaa.en   
/sbin/grep dbdev2 aaaaa.en

Where dbdev2 is a text string in the file being searched for
and aaaaa.en is the file name. 

No switches, no nothing else.  

The first one fails, the second one works on v4.0b, 
(on 3.2g they both worked). 

The strings command only came into it in that if he does a strings and
then pipes it to the failing variant of grep it then works and this 
is used as a work around to make sure he's complying with the man 
pages by only making grep search a bunch of text characters. 


Thanks if you can explain why the two greps seem to behave differently ... 
I didn't even realise we had two different greps until now  :-) 

Details from repro posted below... 


Jo. 

[email protected]> /usr/bin/grep dbdev2 aaaaaaaa.en
[email protected]> /usr/ucb/grep dbdev2 aaaaaaaa.en
[email protected]> /sbin/grep dbdev2 aaaaaaaa.en
dbdev2                  6.1a$2
dbdev2                  6.1a$2
dbdev2                  6.1a$2
[email protected]> uname -a
OSF1 host40b.uvo.dec.com V4.0 564 alpha


[email protected]> /usr/bin/grep dbdev2 aaaaaaaa.en
dbdev2                  6.1a$2
dbdev2                  6.1a$2
dbdev2                  6.1a$2
[email protected]> /sbin/grep dbdev2 aaaaaaaa.en
dbdev2                  6.1a$2
dbdev2                  6.1a$2
dbdev2                  6.1a$2
[email protected]> /usr/ucb/grep dbdev2 aaaaaaaa.en
dbdev2                  6.1a$2
dbdev2                  6.1a$2
dbdev2                  6.1a$2
[email protected]> uname -a
OSF1 host32g.uvo.dec.com V3.2 62 alpha



9918.3Is LANG set?QUARRY::reevesJon Reeves, UNIX compiler groupThu May 22 1997 18:490
9918.4they're built differentlySMURF::WOODBURNThu May 22 1997 19:1425
	Jo,

	/usr/bin/grep and /sbin/grep are built from the same source
	file, grep.c, so you'd think they'd give the same results.
	They should.  They're built from different makefiles though
	and that's the key.

	In V4.0, we added -D_SBCS to the makefile for /usr/bin/grep
	to turn on an optimization in grep.c.  But we forgot to do
	the same in the makefile for /sbin/grep.

	So the reason for the different results is that the two
	greps are following different code paths.  Perhaps one is
	right and one is wrong, or perhaps the "lines" in the binary
	files you're searching are longer than grep's maximum line
	length and the two code paths are just handling that case
	differently.  Not sure.

	I'll QAR this.

	Thanks for posting this, Jo!

	Tom

9918.5qar 53143SMURF::WOODBURNThu May 22 1997 19:320
9918.6BIGUN::nessus.cao.dec.com::MayneA wretched hive of scum and villainyThu May 22 1997 19:447
>        /usr/bin/grep and /sbin/grep are built from the same source
>        file, grep.c, so you'd think they'd give the same results.

sendmail, mailq, and newaliases are built from the same sources, but I don't 
expect them to give the same results.

PJDM
9918.7SMURF::FENSTERYaacov Fenster - System Engineering, Troubleshooting and other mThu May 22 1997 20:2610
                   <<< Note 9918.6 by BIGUN::nessus.cao.dec.com::Mayne "A wretched hive of scum and villainy" >>>
    
    sendmail,mailq,newaliases (and smtpd) are not only built from the same
    sources, they are delivered as the same file with all the above names
    hardlinked to it. /usr/bin/grep and /sbin/grep on the other hand are
    built and delivered as two distinct files.
    
    	Yaacov

    
9918.8finder.uvo.dec.com::COFFEYJLa Feline Flooz - a unix catFri May 23 1997 07:2929
Thanks for the explaination - it all makes a lot more sense now. 
A colleague and I had suposed there were probably different 
libraries being used or something like that. 

So they should both fail, and will in a future version when the 
QAR is implemented - all the more weight to making sure the 
customer does strings piped to grep, jolly good. 

Incidentally LANG didn't appear to be set, if this still makes
a difference. 

Re: sendmail and all the rest - they might be the same sources
but surely like chsh, chfn and passwd they check how they are 
called and behave differently accordingly.  In some ways that's 
no different to saying that tar t, tar c and tar x are all 
built from the same sources isn't it? 

They also have man pages that tell you that dependant on how 
you call them they will behave differently.  The grep man page
however doesn't specify whether it's refering to the 
/usr/ucb, the /usr/bin or the /sbin version which rather 
implies that they are interchangable and behave the same. 

Either way thanks, main objective of this note, expanding my 
knowledge of how these things may differ has been achieved. 

Thanks again 

Jo. 
9918.9BIGUN::nessus.cao.dec.com::MayneA wretched hive of scum and villainyFri May 23 1997 23:424
That was my point: saying that two files use the same sources is meaningless 
without further explanation.

PJDM