Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9059911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:05:22+00:00 2026-06-16T15:05:22+00:00

I’m struggling to create a sed regex command to change lines like this: In

  • 0

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’.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:05:23+00:00Added an answer on June 16, 2026 at 3:05 pm

    Mac and Linux friendly:

    sed -E 's/^([^/][a-zA-Z/_]+\.h)/\/abspaths\/\1/;s/ ([^/][a-zA-Z/_]+\.h)/ \/abspaths\/\1/g' file
    

    Matches 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
    

    Explanation:

    Two substitution are required to account for the extra space needed when the replacement isn’t at the start of the line:

    s/^([^/][a-zA-Z/_]+\.h)/\/abspaths\/\1/;   # First substitution for start of line 
    s/ ([^/][a-zA-Z/_]+\.h)/ \/abspaths\/\1/g  # Second for non-start of line
    
    # Match (first substitution)
    s/
    ^             - start of line
    (             - capture group 
    [^/]          - not a forward slash 
    [a-zA-Z/_]+   - one or more letter, forward slash or underscore
    \.h           - the extension (escaped) 
    )             - end capture group 
    # Replace with 
    /
    \/abspaths\/  - the literal string /abspaths (slashes escaped)
    \1            - the captured group 
    /;
    # Match (second substitution)
    s/
    ' '           - not start of line but a single space (used quotes here for space)
    (             - capture group 
    [^/]          - not a forward slash 
    [a-zA-Z/_]+   - one or more letter, forward slash or underscore
    \.h           - the extension (escaped) 
    )             - end capture group 
    # Replace with 
    /
    ' '           - put the single space back
    \/abspaths\/  - the literal string /abspaths (slashes escaped)
    \1            - the captured group 
    /g            - global flag
    

    Or just by doing one substitution (based on F.Hauri) answer however will only work for one match per line:

    sed -E 's/^(.* )?([^/][^ ]+\.h)/\1\/abspath\/\2/' file
    

    For multiple matches sed supports branching:

    sed -E ':a;s/^(.* )?([^/][^ ]+\.h)/\1\/abspath\/\2/;ta' file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.