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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:50:02+00:00 2026-05-16T16:50:02+00:00

I know that you can use this to remove blank lines sed /^$/d and

  • 0

I know that you can use this to remove blank lines

sed /^$/d

and this to remove comments starting with #

sed /^#/d

but how to you do delete all the comments starting with // ?

  • 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-16T16:50:03+00:00Added an answer on May 16, 2026 at 4:50 pm

    You just need to “escape” the slashes with the backslash.

    /\/\//
    

    the ^ operator binds it to the front of the line, so your example will only affect comments starting in the first column. You could try adding spaces and tabs in there, too, and then use the alternation operator | to choose between two comment identifiers.

    /^[ \t]*(\/\/|$)/
    

    Edit:
    If you simply want to remove comments from the file, then you can do something like:

    /(\/\/|$).*/
    

    I don’t know what the ‘d’ operator at the end does, but the above expression should match for you modulo having to escape the parentheses or the alternation operator (the ‘|’ character)

    Edit 2:
    I just realized that using a Mac you may be “shelling” that command and using the system sed. In that case, you could try putting quotation marks around the search pattern so that the shell doesn’t do anything crazy to all of your magic characters. 🙂 In this case, ‘d’ means “delete the pattern space,” so just stick a ‘d’ after the last example I gave and you should be set.

    Edit 3:
    Oh I just realized, you’ll want to beware that if you don’t catch things inside of quotes (i.e. you don’t want to delete from # to end of line if it’s in a string!). The regexp becomes quite a bit more complicated in that case, unfortunately, unless you just forgo checking lines with strings for comments. …but then you’d need to use the substitution operation to sed rather than search-and-delete-match. …and you’d need to put in more escapes, and it becomes madness. I suggest searching for an online sed helper (there are good regex testers out there, maybe there’s one for sed?).

    Sorry to sort of abandon the project at this point. This “problem” is one that sed can do but it becomes substantially more complex at every stage, as opposed to just whipping up a bit of Python to do it.

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

Sidebar

Related Questions

I know that I can use cmp, diff, etc to compare two files, but
We know that we can use a concept Java Package, but I just wanted
I know that I can use the statement: [string1 rangeOfString:compareString].location!=NSNotFound to check if a
I know that I can use popToRootViewController if I have navigationController in my project
I know that you can use m and then a to add a child
I know that we can use onPause() event to stop the MediaPlayer using reset()
I have a little problem with autoconf, I know that you can use configure.ac
When writing a row-level trigger in Oracle, I know that you can use the
I know that for an integer, you can use: int value; I tried: string
How does printf handle its arguments? I know that in C# I can use

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.