By default, TYPE isbinary, and grep normally outputs either a one-line message saying that a binary file matches, or no message if there is no match. If TYPE is without-match, grep assumes that a binary file does not match; this is equivalent to the -I option. When we want to use grep on a binary file, we’d get errors like this, $ cat /bin/cat grep GLIBC Binary file (standard input) matches. We can ask grep to take binary file as a text with the parameter “-a”, which is equivalent to the –binary-files=text option.
votes
I have binary files that should be text (they're exported logs), but I can't open it with less (it looks ugly - it looks like a binary file). I found that I could open it with vi and I can cat it (you'll see the actual logs), but what I'd really like to do is grep through them (without having to open up each one with vi and then perform a search). Is there a way for me to do that?
Robyn Smith
Robyn SmithRobyn Smith
locked by womble♦Sep 6 '18 at 1:25
This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.
Read more about locked posts here.
5 Answers
votes
You can use
grep anyway to search through the file - it does not really care if the input file is really text or not. From 'man grep':
Please mark the words of caution at the end of the second paragraph. You might want to redirect the results from grep into a new file and examine this with vi / less.
Axel KnaufAxel Knauf
1,53511 gold badge1010 silver badges1212 bronze badges
votes
Pipe it through
strings , which will strip out all of the binary code leaving just the text.
Mike ScottMike Scott
votes
Give quantaquanta
bgrep a try. (original release / more recent fork)
43.8k1515 gold badges116116 silver badges197197 bronze badges
votes
You can use these three commands:
6,4721010 gold badges2222 silver badges4141 bronze badges
MLSCMLSC
vote
Starting with Grep 2.21, binary files are treated differently:
When searching binary data, grep now may treat non-text bytes as line terminators. This can boost performance significantly.
So what happens now is that with binary data, all non-text bytes(including newlines) are treated as line terminators. If you want to change thisbehavior, you can:
Steven PennySteven Penny
Not the answer you're looking for? Browse other questions tagged greptextbinaryparsing or ask your own question.
votes
I have binary files that should be text (they're exported logs), but I can't open it with less (it looks ugly - it looks like a binary file). I found that I could open it with vi and I can cat it (you'll see the actual logs), but what I'd really like to do is grep through them (without having to open up each one with vi and then perform a search). Is there a way for me to do that?
Robyn Smith
Robyn SmithRobyn Smith
locked by womble♦Sep 6 '18 at 1:25
This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.
Read more about locked posts here.
5 Answers
votes
You can use
grep anyway to search through the file - it does not really care if the input file is really text or not. From 'man grep':
Please mark the words of caution at the end of the second paragraph. You might want to redirect the results from grep into a new file and examine this with vi / less.
Axel KnaufAxel Knauf
1,53511 gold badge1010 silver badges1212 bronze badges
votes
Pipe it through
strings , which will strip out all of the binary code leaving just the text.
Mike ScottMike Scott
votes
Give quantaquanta
bgrep a try. (original release / more recent fork)
43.8k1515 gold badges116116 silver badges197197 bronze badges
votes
You can use these three commands:
6,4721010 gold badges2222 silver badges4141 bronze badges
MLSCMLSC
vote
Starting with Grep 2.21, binary files are treated differently:
When searching binary data, grep now may treat non-text bytes as line terminators. This can boost performance significantly.
So what happens now is that with binary data, all non-text bytes(including newlines) are treated as line terminators. If you want to change thisbehavior, you can:
Steven PennySteven Penny
Not the answer you're looking for? Browse other questions tagged greptextbinaryparsing or ask your own question.Comments are closed.
|
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |