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

  • Home
  • SEARCH
  • 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 6128709
In Process

The Archive Base Latest Questions

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

(I use BSD Sed.) This bash script: sed -E -f parsefile < parsewords.d With

  • 0

(I use BSD Sed.)

This bash script:

sed -E -f parsefile < parsewords.d

With this command file:

# Delete everything before BEGIN RTL and after END RTL
\?/\* BEGIN RTL \*/?,\?/\* END RTL \*/?!d   

# Delete comments unless they begin with /*!
s?/\*[^!].*\*/??g       

# Delete blank lines
/^[     ]*$/d

# Break line into words
s/[^A-Za-z0-9_]+/ /g 

# Remove leading and trailing spaces and tabs
s/^[    ]*(.*)[     ]*$/\1/

With this input file:

any stuff
/* BEGIN RTL */

/*! INPUTS: a  b c d ph1   */ /* Comment */
x = a && b || c && d;

    y = x ? a : b;  /* hello */
z = ph1 ? x : z;
  w = c || x || (z || d);
/* END RTL */

Produces this result:

INPUTS a b c d ph1 
x a b c d 
y x a b 
z ph1 x z 
w c x z d 

That’s fine so far but what I’d really like to have is something like this:

x = a && b || c && d; x a b c d
y = x ? a : b; y x a b
z = ph1 ? x : z; z ph1 x z
w = c || x || (z || d); w c x z d

so that the original line is retained along with the mods that the script is making.

Is this possible with sed or should I use something else. (Any other comments are welcome too.)

EDIT: This is not a parsing question. It is about retaining the original input line along with sed modifications.

  • 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-23T16:39:28+00:00Added an answer on May 23, 2026 at 4:39 pm

    A solution using ‘sed’.

    Input file (infile):

    any stuff
    /* BEGIN RTL */
    
    /*! INPUTS: a  b c d ph1   */ /* Comment */
    x = a && b || c && d;
    
        y = x ? a : b;  /* hello */
    z = ph1 ? x : z;
      w = c || x || (z || d);
    /* END RTL */
    

    ‘Sed’ program (script.sed):

    # Delete everything before BEGIN RTL and after END RTL
    \?/\* BEGIN RTL \*/?,\?/\* END RTL \*/?!d   
    
    # Delete comments unless they begin with /*!
    s?/\*[^!].*\*/??g       
    
    # Delete blank lines
    /^[     ]*$/d
    
    # Copy current line in hold space.
    h
    
    # Break line into words
    s/[^A-Za-z0-9_]+/ /g 
    
    # Join both lines with a ';'.
    H ; g ; s/\n/ / ; s/;\s+/; /
    
    # Remove leading and trailing spaces and tabs
    s/^[    ]*(.*)[     ]*$/\1/
    

    Execution:

    $ sed -E -f script.sed infile
    

    Output (I don’t understand the line with the ‘INPUTS’ word, but change the script to adapt it):

    /*! INPUTS: a  b c d ph1   */   INPUTS a b c d ph1 
    x = a && b || c && d; x a b c d 
    y = x ? a : b; y x a b 
    z = ph1 ? x : z; z ph1 x z 
    w = c || x || (z || d); w c x z d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If, under UNIX/Linux/BSD/OSX, I use this sequence of APIs in Application A: msgq_id =
Use case: 3rd party application wants to programatically monitor a text file being generated
use this website a lot but first time posting. My program creates a number
Why does this print garbage instead of exiting my program gracefully? I use system
I am a heavy command line user and use the find command extensively in
I've converted a gnome python script to use KDE notifications every time Spotify changes
I've got a question about use of permissive-licensed (BSD, Apache, MIT, etc) source where
I am currently using the BSD sockets API. I would like to use the
While this question is tagged EventMachine, generic BSD-socket solutions in any language are much
I use BSD socket in my app to send and receive data on iphone4(iOS4.1),there

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.