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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:17:23+00:00 2026-05-27T05:17:23+00:00

When I try to remove some characters in each line using sed , I

  • 0

When I try to remove some characters in each line using sed, I want to see what to be removed in advance using sed, what should I do? for example,
I have a source code file like below, and I want to remove the line numbers at the beginnings:

            102.      for (int i=0; i < args.length; ++i) {
            103.        if ("-skip".equals(args[i])) {
                104.          DistributedCache.addCacheFile(new Path(args[++i]).toUri(), conf);
                105.          conf.setBoolean("wordcount.skip.patterns", true);
                106.        } else {
                107.          other_args.add(args[i]);
                108.        }
            109.      }

what can I do with sed to test the regexp for what to be removed later using ‘s'(meaning replaced with empty string)? well, for this specific example, what’s right regexp to remove the line numbers. is it possible to replace them with the right indents for this being source code using sed? that would be powerful!

Thanks.

  • 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-27T05:17:24+00:00Added an answer on May 27, 2026 at 5:17 am

    Since Jaypal already gave an answer showing the changes with an ERE, I’ll give one with a BRE:

    sed 's/^[[:space:]]*[[:digit:]]\+\.//'
    

    I also used POSIX character classes, to show another option and because I find them easier to remember.

    To see exactly what you’re going to change, there are a couple of reasonable possibilities. You could use the same regex with grep -o:

    grep -o '^[[:space:]]*[[:digit:]]\+\.'
    

    This will select only the part of the line that matches the regex, just showing the indented line numbers in this case.

    Another approach would be to use sed again. You can use & to indicate the matching text in the replace string, which lets you indicate the selected regions, e.g. with stars:

    sed 's/^[[:space:]]*[[:digit:]]\+\./***&***/'
    

    which gives:

    ***            102.***      for (int i=0; i < args.length; ++i) {
    ***            103.***        if ("-skip".equals(args[i])) {
    ***                104.***          DistributedCache.addCacheFile(new Path(args[++i]).toUri(), conf);
    ***                105.***          conf.setBoolean("wordcount.skip.patterns", true);
    ***                106.***        } else {
    ***                107.***          other_args.add(args[i]);
    ***                108.***        }
    ***            109.***      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to remove some non-safe characters from a string but i believe i
I am using Linux and intend to remove some files using shell. I have
I have some doubts about what I'm doing. I try to remove pices of
I'm just trying to remove spaces from some line: (jan | feb | mar
I try to remove some XmlElements from my Xml file in C#2.0. I can
Im using theme_user_profile_form($form) and putting in the line unset ($form['timezone']); But it doesnt remove
So, if I try to remove elements from a Java HashSet while iterating, I
We're re-evaluating our database upgrade process for our application to try and remove the
I got dtd in file and I cant remove it. When i try to
I`m a new guy to c# and I try to add a some code

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.