Re: Strange grep behavior

From: Adam Price (adam+usenet_at_pappnase.co.uk)
Date: 11/10/03

  • Next message: Dirk Munk: "Re: A book that explains what is better ultrix or vms."
    Date: Mon, 10 Nov 2003 18:01:32 -0000
    
    

    In news:boo9co$cu4$1@gwdu112.gwdg.de,
    Helge Preuss <spam.preuss@fhi-berlin.mpg.de> typed:
    > Hi,
    > a colleague of mine complained to me that grep does not print
    > lines matching the search expression in some of his files, giving
    > the message "binary file foo.txt matches". Now his files are just
    > plain old text files. What is even stranger, if he renames that
    > file, grep prints the matching lines.
    > Now I was not able to reproduce this behavior, but I found a
    > different unexpected behavior: grepping for a string in a binary
    > file, which i know it exists, two times out of three (different
    > strings) it does not find the search string. The third time, it
    > just prints the string. No line number, no mention of a binary
    > file eiteher.
    > So my questions: Is this behavior known, maybe even documented?
    > More generally, how does grep determine whether a file is a
    > binary?
    > The OS in case is Tru64 5.1a.
    > TIA
    > Helge

    A file is binary if it contains 'non-printing' characters.
    If you look at the description section of the man page..
    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51A_HTML/MAN/MAN1/0170____.HTM
    You will see...

      [Tru64 UNIX] Running grep on a file that is not a text file (for example,
      an .o file) produces unpredictable results and is discouraged.

    So as you can see the results are unpredictable and discouraged.
    As for your colleagues files, have they been anywhere near a
    windows box?
    Are you sure they are plain text?
    If you view the files with cat -v do you see any strange things?

    Hope this helps some,
    Adam


  • Next message: Dirk Munk: "Re: A book that explains what is better ultrix or vms."

    Relevant Pages

    • Strange grep behavior
      ... matching the search expression in some of his files, ... What is even stranger, if he renames that file, grep prints the ... grepping for a string in a binary file, ... find the search string. ...
      (comp.unix.tru64)
    • Re: List files containing a string..
      ... Er, the question was about files containing a string, not about file ... got were responses like man grep, ... What is not readily apparent in the xargs man page is that it ... that is the standard one on FreeBSD has a -r/-R option and even ...
      (comp.unix.bsd.freebsd.misc)
    • Looking for text inside files does not work at all
      ... for an ascii text string in a file. ... Hex-editing the file reveals that there is a string called "reloc" right ... So if text search (aka grep) worked, this should work too shouldn't it? ... That's how it worked in Windows 2000. ...
      (microsoft.public.windowsxp.help_and_support)
    • Re: modifying files using script
      ... specific string with another one. ... This script works well for one file but exits after that. ... so I used fgrep in the example (grep -F may be preferable or required ... as string by fgrep and RE by $editor, ...
      (comp.unix.shell)
    • Re: grep a string
      ... > I am trying a find all occurences of a SUBSTR in string ... > will -b option for grep be useful. ... SUBSTR or not. ... > perl script to find all occurences of SUBSTR.. ...
      (comp.unix.shell)