gc5*_*gc5 13 diff files file-comparison text vimdiff
我试图找到一种方法来确定一个文本文件是否是另一个文件的子集。
例如:
foo
bar
Run Code Online (Sandbox Code Playgroud)
是一个子集
foo
bar
pluto
Run Code Online (Sandbox Code Playgroud)
尽管:
foo
pluto
Run Code Online (Sandbox Code Playgroud)
和
foo
bar
Run Code Online (Sandbox Code Playgroud)
不是彼此的子集...
有没有办法用命令来做到这一点?
此检查必须是交叉检查,并且必须返回:
file1 subset of file2 : True
file2 subset of file1 : True
otherwise : False
Run Code Online (Sandbox Code Playgroud)
Tim*_*imo 13
如果这些文件内容被称为file1
,file2
并且file3
按照外观顺序,那么您可以使用以下单行代码:
# python -c "x=open('file1').read(); y=open('file2').read(); print x in y or y in x"
True
# python -c "x=open('file2').read(); y=open('file1').read(); print x in y or y in x"
True
# python -c "x=open('file1').read(); y=open('file3').read(); print x in y or y in x"
False
Run Code Online (Sandbox Code Playgroud)