如何计算两个文件列表之间的差异

huangapple go评论59阅读模式
英文:

How to calculate the difference between two file lists

问题

在AIX上,我正在使用ksh。
我有两个使用find . -newer file1 > list1find . -newer file2 > list2创建的文件列表。

现在,我怎么样才能得到这两个列表的差异呢?

list1:

.
./iosrv_0.in.gz
./iosrv_0.out.gz
./iosrv_6.err.gz
./iosrv_6.in.gz

list2:

.
./iosrv_0.in.gz
./iosrv_0.out.gz

结果列表应该是这样的:

./iosrv_6.err.gz
./iosrv_6.in.gz

我考虑过使用grep和diff。但是我没有找到使用grep -v来实现这个的方法。而且diff需要对其输出进行重大处理才能实现所需的结果。

我在这里错过了什么吗?

英文:

On AIX i am using ksh.
I have two file lists created with find . -newer file1 > list1 and find . -newer file2 > list2.

How can I now get a difference of those two lists?

list1:

.
./iosrv_0.in.gz
./iosrv_0.out.gz
./iosrv_6.err.gz
./iosrv_6.in.gz

list 2:

.
./iosrv_0.in.gz
./iosrv_0.out.gz

resulting list should be this:

./iosrv_6.err.gz
./iosrv_6.in.gz

I was thinking about grep and diff. I did not find a way to achieve that with grep -v. And diff does require heavy manipulation of its output to achieve demanded result.

What do I miss here?

Note: I cannot target any file extension or the like. The file lists will be completely generic.

答案1

得分: 2

我解决方案是这样的:

comm -1 -3 list1 list2

-1排除了仅在list1中的行,-3排除了两个列表中都存在的行。因此,只有list2中独有的行被输出...

英文:

Well, sometimes you find the answer after asking...

my solution is this:

comm -1 -3 list1 list2

The -1 excludes lines that are only in list1, and the -3 excludes lines that are in both. Thus only the lines exclusively in list2 are output...

huangapple
  • 本文由 发表于 2023年6月27日 18:35:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563993.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定