grep -z: 为什么 \0 没有产生结果?

pmo*_*mor 0 grep regular-expression

设想:

$ cat t0.txt
xxx
yyy

$ man grep | grep '\-\-null\-data' -A1
       -z, --null-data
              Treat the input as a set of lines, each terminated by a zero byte (the ASCII NUL character) instead of a newline.

$ grep -Pzo 'xxx\0yyy' t0.txt
<nothing>

$ grep -Pzo 'xxx\nyyy' t0.txt
xxx
yyy
Run Code Online (Sandbox Code Playgroud)

那么,如果 grep “将输入视为一组行,每行以零字节终止”,那么为什么'xxx\0yyy'不产生结果呢?

Ste*_*itt 6

grep工艺线;默认情况下,它们由 分隔\\n,并且该-z选项指示grep它应该用作\\0行分隔符。

\n

-z 描述给予 的数据grep;它不会改变输入到 的数据grep。您\xe2\x80\x99d 将其与真正用作\\0分隔符的数据一起使用,例如的输出find -print0

\n

即使您的输入数据确实包含\\0,您也无法使用grep选项\\0-z查找grep行内的匹配项,因此它可以与行分隔符匹配。您的\\n模式有效,因为您的输入包含该模式,并且 grep\xe2\x80\x99t 用作\\n行分隔符(因为该-z选项)。

\n