Mit*_*tch 7 shell grep text-processing
目前我有netcat
管道输出tee
,正在写入 output.txt
nc -l -k -p 9100 | tee output.txt
Run Code Online (Sandbox Code Playgroud)
我想监视这个输出,所以我tail -f | egrep -i 'regex'
通过 PuTTY观看它,这样我只能看到相关的位。
我时不时地想清除输出文件。问题出现了,如果我这样做> output.txt
然后再次尝试tail -f | egrep ...
我没有输出。如果我对文件进行 grep,尽管知道应该有匹配项(因为cat output.txt
正确地吐出文件),但我没有得到匹配项
mitch@quartz:~$ grep output.txt -e 'regex'
Binary file output.txt matches
Run Code Online (Sandbox Code Playgroud)
虽然在清空之前output.txt 上的相同命令工作正常。
基本上:>
让grep
我认为我的文件是一个二进制文件,它不会正确搜索。有没有更好的方法来清除文件?
如果唯一的问题是grep
将其视为二进制文件,请告诉grep
搜索它,无论如何:
$ head /bin/bash > out
$ echo "test" >> out
$ grep test out
Binary file out matches
$ grep -a test out
test
Run Code Online (Sandbox Code Playgroud)
来自man grep
:
-a, --text
Process a binary file as if it were text; this is equivalent to
the --binary-files=text option.
Run Code Online (Sandbox Code Playgroud)