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 6733415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:45:57+00:00 2026-05-26T10:45:57+00:00

I wish to replace all the backslashes (which appear on the same line with

  • 0

I wish to replace all the backslashes (which appear on the same line with an include directive) with slashes.

Here’s what I have until now..

echo '#include "..\etc\filename\yes"' | sed 's&\(#include.*\)\\&\1\/&g'

This works as I expect, but the problem is that it replaces only one \ at a time… If I want to replace all three in the above text, I have to run the sed command 3 times… The g flag at the end should make the replacements globally, no?

I’m using sed 4.2.1 on Ubuntu 11.10…

  • 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-05-26T10:45:58+00:00Added an answer on May 26, 2026 at 10:45 am

    The problem is the way you’re matching. The .* is greedy, so it matches the last backslash first and then thinks it’s done. Try this:

    ... | sed '/^#include/s&\\&/&g'
    

    That runs the substitutions only on lines matching the first pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WordPress blog with numerous URL's I wish to replace from this:
I am writing an XSLT transformation in which I wish to use the Replace
I have a Drupal theme called wellington located in \sites\all\themes\wellington. I wish to override
I have a massive amount of repeating code that I wish to replace in
$data contains tabs, leading spaces and multiple spaces. I wish to replace all tabs
I have a series of text fields, which I need to clean of all
I wish to know all the pros and cons about using these two methods.
I have a html string like this: <html><body><p>foo <a href='http://www.example.com'>bar</a> baz</p></body></html> I wish to
I have a huge ASPX web form which has around 100 fields which need
I have a PHP web application built with CodeIgniter MVC framework. I wish to

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.