I’m struggling to create a sed regex command to change lines like this:
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
To this desired output:
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
so,
- only match relative path+filenames that end in .h
- do not match lines that start with a forward-slash (and thus are already absolute paths)
- match multiple occurances per line
- It has become apparent that I need a command that works with Mac OS X‘s BSD sed command.
What is the regex and sed command that I want?
I’m trying to modify gcc output because included header files with errors/warnings generate error stream output with the relative path referenced, not absolute path. With my XCode IDE calling an external build system, the errors occurring in .h files are not ‘clickable’.
Mac and Linux friendly:
Matches desired output:
Explanation:
Two substitution are required to account for the extra space needed when the replacement isn’t at the start of the line:
Or just by doing one substitution (based on F.Hauri) answer however will only work for one match per line:
For multiple matches
sedsupports branching: