linux - 从文件中查找缺失的对

标签 linux sed awk grep

我想通过以下方式从文件中找到缺失的对:

<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 grepuniq:

$ 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/

相关文章:

linux - 使用 Awk 输入大文本文件并输出最常见的单词文本文件?

regex - 以自定义格式保存 ldapsearch 的 Bash 脚本

regex - 使用 sed 根据第 9 列更改第 11 列的值

unix - 在 unix 中的第一行中添加一列

linux - 在 Linux 上显示不包含特定字符串的行

bash - 使用Awk或Sed在特定行的末尾添加语句

bash - 如何在 shell 中解码 URL 编码的字符串?

php - 在从 php 网页调用的 bash 脚本中克隆 git

linux - 如何在管道的两侧使用 sudo -u

linux - 如何从 Linux 脚本中的路径中删除结束文件夹名称?