Skip to main content
convert to python3 now that python 2 is eol. Remove the UTF-8 encoding limitation by opening in binary mode
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

If those file contents are called file1, file2 and file3 in order of appearance and are properly UTF-8 encoded text, then you can do it with the following one-liner:

 # python3 -c "x=open('file1', mode='rb').read(); y=open('file2', mode='rb').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file2', mode='rb').read(); y=open('file1', mode='rb').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file1', mode='rb').read(); y=open('file3', mode='rb').read(); print(x in y or y in x)"
 False

If those file contents are called file1, file2 and file3 in order of appearance and are properly UTF-8 encoded text, then you can do it with the following one-liner:

 # python3 -c "x=open('file1').read(); y=open('file2').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file2').read(); y=open('file1').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file1').read(); y=open('file3').read(); print(x in y or y in x)"
 False

If those file contents are called file1, file2 and file3 in order of appearance, then you can do it with the following one-liner:

 # python3 -c "x=open('file1', mode='rb').read(); y=open('file2', mode='rb').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file2', mode='rb').read(); y=open('file1', mode='rb').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file1', mode='rb').read(); y=open('file3', mode='rb').read(); print(x in y or y in x)"
 False
convert to python3 now that python 2 is eol.
Source Link
Stéphane Chazelas
  • 584.9k
  • 96
  • 1.1k
  • 1.7k

If those file contents are called file1, file2 and file3 in order of apearanceappearance and are properly UTF-8 encoded text, then you can do it with the following one-liner:

 # pythonpython3 -c "x=open('file1').read(); y=open('file2').read(); print (x in y or y in x"x)"
 True
 # pythonpython3 -c "x=open('file2').read(); y=open('file1').read(); print (x in y or y in x"x)"
 True
 # pythonpython3 -c "x=open('file1').read(); y=open('file3').read(); print (x in y or y in x"x)"
 False

If those file contents are called file1, file2 and file3 in order of apearance then you can do it with the following one-liner:

 # 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

If those file contents are called file1, file2 and file3 in order of appearance and are properly UTF-8 encoded text, then you can do it with the following one-liner:

 # python3 -c "x=open('file1').read(); y=open('file2').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file2').read(); y=open('file1').read(); print(x in y or y in x)"
 True
 # python3 -c "x=open('file1').read(); y=open('file3').read(); print(x in y or y in x)"
 False
Source Link
Timo
  • 6.5k
  • 1
  • 28
  • 30

If those file contents are called file1, file2 and file3 in order of apearance then you can do it with the following one-liner:

 # 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