简体   繁体   中英

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.

How can I remedy this problem?

Example:

例子

Skip the ID column when doing the comparison. You can use process substitution for this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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