3
I have an executable that generates a text file as its output. The problem is that the text file comes out with a binary file flag of some sort. The result is something like this:
$ grep "grep string" output_file.txt
Binary file output_file.txt matches.
$ grep -a "grep string" output_file.txt
[correct results]
Some reading has indicated that grep looks for a null character in the first thousand or so bytes, then determines from that whether or not a file is 'binary', so my question is two-fold:
Is there an easy way to strip null characters from my files (I can do this as part of my post-processing) to ensure that grep works correctly without the -a flag?
Is there something obvious I should look for in my code to prevent null characters from being written to the file? I've looked through the code quite thoroughly and I don't see any obvious culprits.
.
I would vote this up if I could, but I'm apparently too new. :-/ – brightwellcd – 2011-08-18T16:53:18.983
I found a null string in my output. I ran this tr script and did a visual diff; quickly found the problem. I'll upvote this if/when I get enough reputation to do so. Thanks. – brightwellcd – 2011-08-18T17:58:08.740