grep - 在 XML 中搜索所有子目录的值并返回子目录名称和值
问题描述
例子
目录路径:/this/dir/contains/
子目录:sub1;子2;子3
在每个子目录中都有一个 xml:hello.XML
/this/dir/contains/sub1/hello.XML
在 hello.XML 中有一个如下所示的字符串: Zipper="YYZ"
请注意,每个 hello.XML 中的值“YYZ”可能不同
我可以使用 grep 在每个 hello.XML 中返回子目录名称和“Zipper”值吗
解决方案
使用选项“ -R ”递归搜索列出的子目录。
bash-3.2$ pwd
/Users/anku/Documents/project
bash-3.2$ cat sub1/sub1.xml
Some line
Zipper="HELLO1"
some line
bash-3.2$
bash-3.2$ cat sub2/sub2.xml
Some line
Zipper="HELLO2"
some line
bash-3.2$ cat sub3/sub3.xml
Some line
Zipper="HELLO3"
some line
bash-3.2$
bash-3.2$ grep -Ri "Zipper" *
sub1/sub1.xml:Zipper="HELLO1"
sub2/sub2.xml:Zipper="HELLO2"
sub3/sub3.xml:Zipper="HELLO3"
bash-3.2$
请在询问时也添加您的努力。祝你好运
推荐阅读
- php - 如何在 PHP/Laravel 中删除多个值为 0 的数组
- mongodb - 无法从 Ubuntu 安装/删除任何东西
- android - 如何通过 URL 将图像下载到内部存储器?
- sql - 从 dt=2018-12-01T18:23:59.000Z 到 dt 的 Hive 日期转换 - 5 小时,格式为 12/1/2018 13:23(即 'MM/dd/yyyy hh:mm' )
- antlr4 - Antlr4:用双点解析点尾浮点数
- html - 多列无序列表
- r - R Shiny:如何选择动态闪亮输入
- javascript - 为什么以下代码中的警报没有执行:?
- apache-nifi - 使用 docker-compose 时找不到 NiFI 的集群管理菜单
- opencv - pytesseract 已安装但丢失?