I'm working with a Windows-10 computer, using a WSL.
I'm investigating a logfile, produced by NLog
in a C# application. I'm expecting log entries to appear everywhere throughout the file, but I see the following:
Linux prompt> grep "geen mengcontainer" logfile.log
2023-03-07 07:25:08.7971 | Warn | ... | geen mengcontainer.
2023-03-07 07:25:09.8285 | Warn | ... | geen mengcontainer.
2023-03-07 07:25:10.8754 | Warn | ... | geen mengcontainer.
Binary file logfile.log matches
As you see, after 07:25:10, the grep
stops, even though the file goes further for the rest of the day. There seems to be some character, telling grep
that the file is not a textfile, but a binary file, causing grep
to stop working.
Some more information about the file:
Linux prompt>file logfile.log
logfile.log: ASCII text, with CRLF line terminators
Some more information about my Linux WSL installation:
Linux prompt>uname -a
Linux ComputerName 4.4.0-19041-Microsoft
#2311-Microsoft Tue Nov 08 17:09:00 PST 2022
x86_64 x86_64 x86_64 GNU/Linux
Linux prompt> cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
...
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
Some more information about my grep
installation:
Linux prompt> grep --version
grep (GNU grep) 3.4
What can I do?
- Does anybody know how to find and replace the character, which is responsible for
grep
to stop filtering? - Does anybody know which extra parameter or switch I can add to
grep
in order not to stop filtering? - Does anybody know about a
grep
version which does not behave like this? (Please take into account thatapt update
things don't work on my environment)
Thanks in advance
-a
), but consider that with a different approach you would easily find the answer yourself. You mention you're looking for a grep flag to change handling of binary files; the obvious place to look for that isman grep
. But it's a long man page, and nobody wants to read it all. So, try searching it for "inary" with/inary
(this catches both "Binary" and "binary"). This turns up the answer straight away.-a
switch, which is indeed a good way to handle my particular problem, hence my acceptance and upvote of the answer. To that, I have added an instruction on how to make sure that the-a
switch is always used. Apparently some people don't agree with that, but you can leave it up to the answer author to decide about rejecting or approving the edit.less
) to make/
searches case insensitive, you can just search forbinary
. The less option is-i
, which you can put in aLESS=-i
environment variable, or your~/.lesskey
. I putLESS = iMRj5X
in that startup file to use a more verbose prompt, and make searching put the target line at line 5 instead of the top so I can see context, etc. I also bind,
and.
to prev/next file (less used to compile that init file to a binary to minimize startup time, but that's no longer a thing.)