【发布时间】:2012-12-30 22:22:03
【问题描述】:
我正在努力创建一个 sed 正则表达式命令来更改这样的行:
In file included from dira/file_a.h:8, dire/file_e.h:9, and dirf/file_f.h:10,
from dirb/file_b.h:6,
from /existing/abs/path/dirb/file_b.cc:6:
dirc/file_c.h:88: error: 'eqn_count_t' does not name a type
dirc/file_c.h:95: error: 'wave_count_t' does not name a type
dirc/file_c.h:104: error: ISO C++ forbids declaration of 'WmHyperbolicEqnSet' with no type
到这个想要的输出:
In file included from /abspaths/dira/file_a.h:8, /abspaths/dire/file_e.h:9, and /abspaths/dirf/file_f.h:10,
from /abspaths/dirb/file_b.h:6,
from /existing/abs/path/dirb/file_b.cc:6:
/abspaths/dirc/file_c.h:88: error: 'eqn_count_t' does not name a type
/abspaths/dirc/file_c.h:95: error: 'wave_count_t' does not name a type
/abspaths/dirc/file_c.h:104: error: ISO C++ forbids declaration of 'WmHyperbolicEqnSet' with no type
所以,
- 只匹配以.h结尾的相对路径+文件名
- 不匹配以正斜杠开头的行(因此已经是绝对路径)
- 每行匹配多次出现
- 很明显,我需要一个与 Mac OS X 的 BSD sed 命令配合使用的命令。
我想要的 regex 和 sed 命令是什么?
我正在尝试修改 gcc 输出,因为包含错误/警告的头文件会生成错误流输出,其中引用了相对路径,而不是绝对路径。使用我的 XCode IDE 调用外部构建系统,.h 文件中发生的错误不是“可点击的”。
【问题讨论】:
-
标题与您的问题不符。
/abspath/dirb/file_b.cc不在行首,也不以.h结尾 -
哎呀,你是对的。我不在乎行首,我会编辑标题。
标签: regex bash sed osx-mountain-lion