Grep 与 More 结合的不确定性行为

Grep 与 More 结合的不确定性行为

您期望在此之后发生什么:

for /l %i in (1,1,100) do @more some.bbl | grep a | md5sum

最可能,不是这:

ec3ecb76408d4225ff23a25d0596e00f *-
13cfd899b90b9cd7aedb406a785e8eac *-
737e8898a65657f1a2ce8012ff1ffe82 *-
d4095243e56a7da3b31a352423a5417a *-
319db7810e677414ca1609238bdeba6f *-
31e626a8ce0732fda1fa7499c8b13dfa *-
006fe390f923d50348d65d0bbefa64d8 *-
77708f62cb2d61a45788a656d0979aee *-
cda10a9ab71c2bce4df069c479241349 *-
b01b71dc7dca11808ca989c4985513ca *-
c22a6f8b1cac9a93c4fe10b07a9f483a *-
0b04f4b24f3f183270eb7414f4f86e3d *-
5a2f8b8ad482ae8f70b7ce3384a7c9e2 *-
beccdbe737b48c02b48c4524cd89eede *-
a16fec5238cfe8dfff6b403ff943a8ca *-
ec0cd2edc0009abd14119915a8b563f4 *-
1e78f0012ca09aeade169f815415da40 *-
...

我也很担心,因此我进行了一些健全性检查:

for /l %i in (1,1,100) do @more some.bbl | md5sum

收益率 100 倍

ace4f37f3a1433e29696a535c0b79f2c *-

同样

for /l %i in (1,1,100) do @grep a some.bbl | md5sum

d8753d755025a1119cd2910c6f5cb0de *-

因此moregrepmd5sum本身就可以正常工作。此外,之前的管道md5sum也不是问题,因为

for /l %i in (1,1,100) do @more some.bbl | grep a > out%i
md5sum out*

确认了问题。fc查看输出后,我发现没有区别。diff查看它们发现了看不见的差异,经十六进制编辑器确认,这些差异是看似随机的位置的行尾差异(并且因文件而异)。

在本例中,这个问题仍然会出现,但是不太常见:

for /l %i in (1,1,100) do @more some.bbl | grep "[a-z]" | md5sum

屈服

b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
ef23817185d41987c11cb1fc4371bb76 *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
e398e63b60cee3e271967f01350068f1 *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
b135bcfe0bcfb7f1c43fe1905164c31e *-
...

现在我不知道原因是什么了。如果我没有丢失任何有效的行,我不会在意这么多,例如:

for /l %i in (1,1,100) do @more "some.bbl" | grep "\}$" | wc -l

这给出

249
249
249
248
255
253
252
248
251
...

要重现类似的问题,您可以使用此文件

for /l %i in (1,1,200) do @echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX{Something1999a}>> some.bbl

更多信息

C:\>ver

Microsoft Windows [Version 6.1.7601]

C:\>more /h

Displays output one screen at a time.

MORE [/E [/C] [/P] [/S] [/Tn] [+n]] < [drive:][path]filename
...

C:\>grep --ver

GNU grep 2.6.3

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

C:\>md5sum --ver

md5sum (GNU coreutils) 8.15
Packaged by Cygwin (8.15-1)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later     <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Ulrich Drepper, Scott Miller, and David Madore.

为什么会发生这种情况?

更新:more通过替换以下内容,问题也会消失cat

C:\>cat --ver

cat (GNU coreutils) 8.15
Packaged by Cygwin (8.15-1)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjörn Granlund and Richard M. Stallman.

相关内容