简体   繁体   English

比较 Bash 脚本中的两个文件

[英]Compare two files in Bash Script

I have a problem when comparing two files, which I do by using the command:比较两个文件时遇到问题,我使用以下命令:

diff file1.csv file2.csv >> outputfile.csv 

Everything works correctly.一切正常。 The problem is, if there's a line missing in one of them, my IDs start to differ/are no longer the same and everything is shifted, so diff returns every line after the shift.问题是,如果其中一个缺少一行,我的 ID 开始不同/不再相同并且所有内容都被转移,因此diff在转移后返回每一行。

How can I remedy this problem?我该如何解决这个问题?

Example:例子:

例子

Skip the ID column when doing the comparison.进行比较时跳过 ID 列。 You can use process substitution for this.您可以为此使用流程替换。

diff <(cut -d, -f2- file1.csv) <(cut -d, -f2- file2.csv)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM