Currently I have netcat
piping output to tee
which is writing to output.txt with
nc -l -k -p 9100 | tee output.txt
I want to monitor this output, so I'm watching it with tail -f | egrep -i 'regex'
via PuTTY so that I only see relevant bits.
Every now and then I want to clear the output file. The issue arises that if I do > output.txt
and then again try to tail -f | egrep ...
I get no output. If I grep through the file, I get no matches, despite knowing that there should be matches (as cat output.txt
spits out the file properly)
mitch@quartz:~$ grep output.txt -e 'regex'
Binary file output.txt matches
While the same command on output.txt before emptying it works fine.
Basically: >
makes grep
think my file is a binary file and it won't properly search. Is there a better way to clear the file?
Best Answer
If the only problem is that
grep
treats it as binary, tellgrep
to search it regardless:From
man grep
: