allegro

Linux文件合并、去除重复

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

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

  cat file1 file2 | sort | uniq > file3

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

  cat file1 file2 | sort | uniq -d > file3

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

  cat file1 file2 | sort | uniq -u > file3

 

二、两个文件合并

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

  cat file1 file2 > file3

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

  paste file1 file2 > file3

 

三、一个文件去掉重复的行

1. 重复的多行记为一行

  sort file |uniq

2. 重复的行全部去掉

  sort file |uniq -u

 

分类:

技术点:

相关文章:

  • 2021-12-15
  • 2022-12-23
  • 2021-07-07
  • 2022-02-03
  • 2022-12-23
  • 2021-12-18
猜你喜欢
  • 2021-12-19
  • 2022-02-02
  • 2021-12-09
  • 2021-12-09
  • 2022-01-18
  • 2021-12-09
相关资源
相似解决方案