跳到主要内容

文件对比

两个文件的交集、并集(前提条件:每个文件中不得有重复行)

  1. 取出两个文件的并集(重复的行只保留一份)

cat file1 file2 | sort | uniq > file3

  1. 取出两个文件的交集(只留下同时存在于两个文件中的文件)

cat file1 file2 | sort | uniq -d > file3

  1. 删除交集,留下其他的行

cat file1 file2 | sort | uniq -u > file3

两个文件合并

  1. 一个文件在上,一个文件在下

cat file1 file2 > file3

  1. 一个文件在左,一个文件在右

paste file1 file2 > file3

一个文件去掉重复的行

  1. 重复的多行记为一行

sort file |uniq

  1. 重复的行全部去掉

sort file |uniq -u

来源

http://www.cnblogs.com/allegro/archive/2011/05/23/2054252.html