0

我正在比较 2 个长度不同的文件,但我不想在较短的文件结束后看到较长文件的输出。尽管我确实需要知道在较短文件结束之前任一文件上是否缺少行。

我不必使用差异,我可能会使用 python 来做到这一点,有没有简单的方法在 python 上做同样的事情?

4

1 回答 1

1

看看这个解决方案是否适合你:

dhruvpathak@dhruvpathak:~$ cat shortfile
this is a
short file
created
for example
dhruvpathak@dhruvpathak:~$ cat longfile
this is a
long file
created
for example.
but also contains
some extra text
which needs to be
ignored when
the small file 
ends.

dhruvpathak@dhruvpathak:~$ cat shortfile > /tmp/a && echo "*****ENDMARKER*****" >> /tmp/a && cat longfile > /tmp/b && diff /tmp/a /tmp/b | grep -B 100000 "*****ENDMARKER*****"
2c2
< short file
---
> long file
4,5c4,10
< for example
< *****ENDMARKER*****
于 2013-07-10T06:07:01.343 回答