【发布时间】:2017-10-20 00:48:24
【问题描述】:
我试图编写一个 bash 脚本以便在这个文件上应用正则表达式。
somedir1/include/log.h:65:inline void ERROR(int, const std::string&) {}
somedir1/common/packet.cpp:68: ERROR(1, "File couldn't be opened");
anotherdir2/core/client.cpp:380: ERROR(error, "Connection error");
otherdir3/src/client.cpp:534: ERROR(1, "Wrong command");
但是,我无法设法将目录名称收集为变量。
我拥有的最后一个稳定的正则表达式材料是:
[^,]*\/[^,]*:[0-9]*:[^,].*\n
#[^,]--->This one is the one I am interested in.
我的目标是将共享同一父目录的条目分组到同一文件中。比如;
fileName: report_somedir1
content: somedir1/include/log.h:65:inline void ERROR(int, const std::string&) {}
content: somedir1/common/packet.cpp:68: ERROR(1, "File couldn't be opened");
将第一个模式存储为变量的正确方法是什么? 提前感谢您的时间和耐心。
【问题讨论】:
-
您想要的输出与您的示例输入不匹配。如果您使两者完全一致,您可能会得到更好的答案。
-
@John1024 不是吗?
-
确实匹配。文件名和内容是为了引导人。
-
@123 字符串
report_somedir1出现在输出中,但不在输入中。字符串client.cpp在输入中出现两次,但在输出中没有出现一次。 -
report_somedir1 是输出文件的示例名称。不是输出本身。由于我们按 somedir1 对它们进行了分组,并且 client.cpp 属于其他目录,因此我们在此输出中看不到它们。为什么人们不阅读@John1024就分享破坏性的cmets