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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:25:36+00:00 2026-05-22T11:25:36+00:00

This is an extension of my previous question recommended by the answerer. Basically, I

  • 0

This is an extension of my previous question recommended by the answerer. Basically, I need sed to print text between delimiters. The delimiters could span multiple lines like:

(abc
d)

Below are sample input and output.

Input

(123) 
aa (a(b)cd)) (g) (c)fff 
abcd(aabb 
d)aa (aeb)oe

correct output

123
a(b  
aabb
d

Note: I only want the text between the first pair of delimiters. If the delimiter spans two lines than I just want the text between first pair that span two lines and move on to the third (next) line. Thus, for the last line in the input I printed ‘d’ and skip (aeb) and move on to the next line.

  • 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-22T11:25:36+00:00Added an answer on May 22, 2026 at 11:25 am

    I used a sed script file (called sedscript) containing:

    /^[^(]*([^)]*$/N
    s/^[^(]*(\([^)]*\)).*/\1/p
    

    and the command line:

    sed -n -f sedscript data
    

    Given the input:

    (123)
    aa (a(b)cd)) (g) (c)fff
    abcd(aabb
    d)aa (aeb)oe
    

    It produced the output:

    123
    a(b
    aabb
    d
    

    You can do it on a single command line with:

    sed -n -e '/^[^(]*([^)]*$/N' -e 's/^[^(]*(\([^)]*\)).*/\1/p' data
    

    The first pattern looks for lines containing an open parenthesis without a close parenthesis after it, and reads the next line into memory and starts over. It repeats that until there is a close parenthesis in the data (or EOF). The second pattern looks for the stuff before an open parenthesis, the open parenthesis, remembers the data from there to the first close parenthesis, followed by the close parenthesis and any other stuff; it replaces that with the remembered string and prints it. Anything else is not printed (-n).

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

Sidebar

Related Questions

This question is basically an extension of my previous question . I asked the
Hello every one this is basically extension to my previous question. i have write
An extension to my previous question: Text cleaning and replacement: delete \n from a
(Note: This is an extension of a previous question .) I am having some
This is an extension to a previous question which was answered. But have a
This is a question that is an extension of my previous Free 3 of
this is an extension to a previous question I asked , today .... which
This is an extension to my previous question . I've successfully added a button
this question is an extension of my previous question that you can find here:
This question is an extension of a previous question: Return an object in VBA

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.