从命令管道 grep 将输出重定向到文件

Rus*_*mov 9 command-line bash grep

我正在运行这个:

cat /dev/urandom|hexdump| grep -i "ffff f" > random

我在文件中什么也没有,random在命令中断后它保持零长度。

如何使其将输出写入文件?

我需要将结果写入一个文件,该文件应包含如下输出数据:

021bc40 7724 d4f5 59ec bcbb ffff fd26 ab3c 9b7c

03a9100 b3a5 8601 fa33 ffff f23c 4326 2e7f 0c8a

0449810 e459 d5af 4e11 ffff fc55 8660 9efb 3c9b

在此处输入图片说明

Dub*_*ubu 16

使用--line-buffered选项grep(并去掉无用的cat):

hexdump /dev/urandom | grep --line-buffered -i "ffff f" > random
Run Code Online (Sandbox Code Playgroud)

这样输出不会被缓冲,而是random立即输入每一行。我还建议tee在您的管道中使用以查看已生成多少行:

hexdump /dev/urandom | grep --line-buffered -i "ffff f" | tee random
Run Code Online (Sandbox Code Playgroud)