1. 打印出在文件test1中存在而 test2中不存在的用户
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