1.csv:
rundeck-read-only-iam-permissions,IAMReadOnlyAccess
citrix-xendesktop-ec2-provisioning",AmazonEC2FullAccess
2.csv:
citrix-xendesktop-ec2-provisioning",AmazonEC2FullAAA
citrix-xendesktop-ec2-provisioning",AmazonS3FullAccess
rundeck-read-only-iam-permissions,IAMReadOnlyAccess
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq,qqqqqqqqqqqqqqqq
注意顺序不一样
我想比较文件 2.csv 与文件 1.csv 中的差异(以及 2.csv 中的订单行以匹配 1.csv 中的订单)
如果没有更改,则打印: 如果文件 1.csv 中的行发生更改,则不会更改 打印已更改的行+行内容,如果文件 1.csv 中的行丢失,则打印“已删除的行 + 行内容,如果行在添加文件 1.csv 打印“已添加行”+行内容,到目前为止,我有这个,它打印所需的输出,但是否可以检测添加/删除的内容
comm -1 -3 <(sort 1.csv) <(sort 2.csv)
citrix-xendesktop-ec2-provisioning",AmazonEC2FullAAA
citrix-xendesktop-ec2-provisioning",AmazonS3FullAccess
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq,qqqqqqqqqqqqqqqq
答案1
diff
可能是您想要的工具。以下是三个示例文件:
$ paste foo bar baz
aaa aaa aaa
aaa aaa aaz
aaa aaa aaa
$ if diff <(sort foo) <(sort bar); then echo "No differences"; fi
No differences
$ if diff <(sort foo) <(sort baz); then echo "No differences"; fi
3c3
< aaa
---
> aaz