我正在比较两个长度不同的文件但我不希望在较短的文件结束后看到较长文件的输出。 虽然我确实需要知道在较短文件结束之前是否有任何文件中缺少行。
我没有必要使用diff,我可能会使用python来做这个,有没有一种简单的方法在python上做同样的事情?
答案 0 :(得分: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*****