标签:grep with open for code one zha 打印 pytho read
BJ$ cat test1
shi
zhen
ning
zhang
san
li
si
yan
jun
BJ$ cat test2
zhang
san
li
si
yan
jun
BJ$ cat diff.py
#!/usr/bin/python
with open(‘/Users/momo/test1‘,‘r‘) as x:
list1 = x.readlines()
with open(‘/Users/momo/test2‘,‘r‘) as y:
list2 = y.readlines()
for i in list1:
if i not in list2:
print i
执行:
BJ$ python diff.py
shi
zhen
ning
shell:
BJ$ cat 1.sh
#!/bin/bash
for i in `cat test1`
do
temp=`grep $i test2`
if [ -z $temp ];then
echo $i
fi
done
标签:grep with open for code one zha 打印 pytho read
原文地址:https://blog.51cto.com/magic3/2480057