shell编程(4)

写脚本实现,可以用shell、perl等。把文件b中有的,但是文件a中没有的所有行,保存为文件c,并统计c的行数。

用grep实现

grep -xvFf a b | tee c | wc -l

grep -x 匹配一整行
grep -v 逆匹配,即寻找不匹配的
grep -F 从文件中匹配
grep -f 带匹配的字符串存放在文件中

grep -xvFf a b 表示:从文件b中匹配文件a中的每一行(由于有v,指不匹配的行,即b有a没有的行)
tee c 表示: Copy standard input to each FILE, and also to standard output. 写入文件的同时写入标准输出,供wc -l 使用。 wc -l 计算行数。

猜你喜欢

转载自caoruntao.iteye.com/blog/1167836