Recently, the marketing department's colleagues asked me to help deal with a two files, to determine whether the content of a file exists in the B file, if there is the content of the B file, think of the next, the shell is very simple implementation, with Python how to achieve it? Here is the specific code:
Shell code:
#!/bin/bashfor line in ' cat/root/zy/audiolist.txt ' do files= ' Cat/root/zy/list.txt|grep "$line" |wc-l ' if [-N $ Files] then echo ' cat/root/zy/list.txt|grep ' $line ' >> shell-script.txt else echo ' file is not exist "Fidone
Shell script output input directly into file Shell-script.txt
python code:
#!/usr/bin/env pythonfobj=open ('/root/zy/python-secipt.txt ', ' rw+ ' ) With open ('/root/zy/audiolist.txt ', ' R ') as f: for line In f: with open ('/root/zy/list.txt ', ' R ') as obj: for strs in obj.readlines (): if Line.strip () in strs.strip (): fobj.write (Strs.strip () + "\ n") Fobj.close ()
The Python script directly outputs the file to Python-secipt.txt
This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1893441
Python determines whether a string in a file exists in another file