我想通过以下方式从文件中找到缺失的对:
<itemA>
<idA="312" />
</itemA>
<itemB>
<idB="312" /> # has a corresponding itemA
</itemB>
<itemB>
<idB="313" /> # doesn't have a corresponding itemA
</itemB>
我什至不确定为此使用什么工具(sed、awk、grep)。
最佳答案
使用 GNU grep
和 uniq
:
$ grep -Po '(?<=id[AB]=")[0-9]+' file | uniq -u
313
如果您的输入未按排序顺序:
$ grep -Po '(?<=id[AB]=")[0-9]+' file | sort -n | uniq -u
313
关于linux - 从文件中查找缺失的对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16769523/