Hi Eric,

Thanks for the reply.

This grep version does provide a --binary switch.  But, when using that,
grep does not bring back the rows containing my search string.  Instead,
I get:

        C:\temp>grep --binary "^.\{384\}M" monthly.transac.tions
        Binary file monthly.transac.tions matches

The file I'm grepping is a little strange.  It's a Windows DOS file
containing binarye data with CRLF separating the lines.  So, if I tell
it to treat the file as text (--text), grep selects the correct rows,
but it then adds the x'0D' to the end of each row.  Here is that syntax:

        C:\temp>grep --text "^.\{384\}M" monthly.transac.tions
>results.out

Thanks, Gary

-----Original Message-----
From: Eric Blake [mailto:[email protected]] 
Sent: Wednesday, June 20, 2012 3:44 PM
To: Gary Aderhold
Cc: [email protected]
Subject: Re: grep to a file adds x'0D'

On 06/20/2012 07:42 AM, Gary Aderhold wrote:
> I'm using GNU grep 2.5.4.  I'm grepping a binary file in Windows that 
> has record delimiters of CRLF  (x'0D 0A').  My grep selects the proper

> rows, but, when sending the results to a file, it's adding a CR to the

> end of each record.  So, now my records all end with x'0D 0D 0A'.

That sounds like a case of your version of grep opening input files in
binary mode, but output files in text mode.  Either grep should open ALL
files in binary mode, or ALL files in text mode (and I prefer binary
mode, as it is less likely to strip CR when I want it preserved).

But this is not a bug in upstream grep.

> 
> Is this a bug?  Or, is there a way to tell grep to NOT add this extra 
> x'0D' byte?

You'll need to investigate this with whoever made the particular grep
binary for windows, and figure out why their port is mixing binary and
text modes.  They may have also provided a --binary command-line option,
and if using that option fixes your problems, you have a workaround.

-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org




Reply via email to