linux - 使用 shell 或 diff 命令从两个 csv 文件中提取修改和添加的行

标签 linux bash shell diff

我有两个 csv 文件 F1 和 F2,它们的行顺序相同,我想通过比较文件 F1 和 F2 与 F2 来提取更改/添加的行。

我尝试了 diff 命令,但我可以看到变化。我如何读取模式并从 F2 中提取行?

F1(文件 1):

1234,Joe,pieter,joe@gmail.com,male,22
1235,Shally,Jonse,shally@yahoo.com,female,24
1235,Harry,poter,harry@gmail.com,male,21
1235,Helen,Jairag,helen@gmail.com,female,21
2585,Dinesh,Jairag,helen@gmail.com,female,21

F2(文件2):

1234,Joe,pieter,joe@gmail.com,male,22
1235,Shally,Jonse,shally@yahoo.com,female,24
1235,Harry,Potter,harry@gmail.com,male,21
1235,Helen,Jairag,helen@gmail.com,female,21

执行的命令:

diff F2 F1

输出:

3c3
< 1235,Harry,Potter,harry@gmail.com,male,21
---
> 1235,Harry,poter,harry@gmail.com,male,21
4a5
> 2585,Dinesh,Jairag,helen@gmail.com,female,21

文件 F3 中的预期输出:

1235,Harry,poter,harry@gmail.com,male,21
2585,Dinesh,Jairag,helen@gmail.com,female,21

最佳答案

diff --changed-group-format='%<' --unchanged-group-format='' file1 file2

关于linux - 使用 shell 或 diff 命令从两个 csv 文件中提取修改和添加的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12069809/

相关文章:

bash - 通过 ssh 获取以 nohup 启动的进程的 PID

python - boost python sleep wrapper导致整个python程序进入休眠状态

linux - I2C 设备驱动程序错误 [TCA6408 I/O 扩展器]

Python 日志记录 - 以格式保存到文件

linux - 为什么 sed 将此替换的结果评估为 8?

linux - 多次运行脚本并将输出保存在多个文件夹中

linux - 解析 bash 脚本中的文本

linux - CentOS : How to uninstall gerrit server from CentOS release 6. 4

linux - Unix - 如何对一个词使用 cut -d

python - 存储 GNU 时间命令和脚本的输出