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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:42:16+00:00 2026-06-13T06:42:16+00:00

I’m writing a script to convert some code. I have a sed command that

  • 0

I’m writing a script to convert some code. I have a sed command that performs the proper conversion however I need to use the -n command to prevent automatic printing of pattern space to suppress double printing. Yet this then prevents printing any of the other lines that I want to be output. This is the script I’m using.

sed -i -r 's/^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,[ ]*(I((.[A-z]+)+)),[ ]*\{/ class \4 extends \5 { /p
/^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,/ {
N
s/ *\n/ /
s/^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,[ ]*(I((.[A-z]+)+)),[ ]*\{*/ class \4 extends \5 { \
/p
}
'

A test input file can be found here: https://www.dropbox.com/s/h9vly1hwtqtl8te/TestText.txt
the two different results from having/not having the -n switch in the script can be found here:https://www.dropbox.com/s/f0g8horafwial1x/TestText.txt.ts_result1.txt
and here: https://www.dropbox.com/s/ekualxj7foapgml/TestText.txt.ts_result2.txt
with the desired results being found here: https://www.dropbox.com/s/3510oh899fh0ji2/TestText.txt.ts_resultdesired.txt

Is it possible to obtain the desired results?

I’m running
$ sed –version
GNU sed version 4.2.1

  • 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-13T06:42:17+00:00Added an answer on June 13, 2026 at 6:42 am

    Another way to prevent double-printing is to place a d after the last print command (allowing you to remove the -n). Also, because you have a conditional after the print, you can use instead the t command, that will branch to a label (in this case the done label before the d command) when the previous substitute succeeds (ie. it printed something already).

    sed -i -r 's/^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,[ ]*(I((.[A-z]+)+)),[ ]*\{/ class \4 extends \5 { /p
    /^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,/ ! t done
    /^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,/ {
    N
    s/ *\n/ /
    s/^[ ]*Class[(]"(I((.([A-Za-z]+)))+)"[ ]*,[ ]*(I((.[A-z]+)+)),[ ]*\{*/ class \4 extends \5 { \
    /p
    : done
    d
    }
    '
    

    (Note: Not tested this though…)

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need 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.