英文:
How to calculate the difference between two file lists
问题
在AIX上,我正在使用ksh。
我有两个使用find . -newer file1 > list1
和find . -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...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论