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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:56:46+00:00 2026-05-22T02:56:46+00:00

This is an extension of my previous question . In that question, I needed

  • 0

This is an extension of my previous question. In that question, I needed to retrieve the text between parentheses where all the text was on a single line. Now I have this case:

(aop)
(abc
d)

This time, the open parenthesis can be on one line and the close parenthesis on another line, so:

(abc
d)

also counts as text between the delimiters ‘( )‘ and I need to print it as

abc
d

EDIT:
In response to possible confusions of my question, let me clarify a little. Basically, I need to print text between delimiters which could span multiple lines.

for example I have this text in my file:

randomtext(1234
567) randomtext
randomtext(abc)randomtext

Now I want Sed to pick out text between the delimiter “(” and “)”. So the output would be:

1234
567
abc

Notice that the left and right brackets are not on the same line but they still count as a delimiter for 1234 567, so I need to print that part of the text. (note, I only want the text between the first pair of delimiters).

Any help would be appreciated.

  • 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-22T02:56:47+00:00Added an answer on May 22, 2026 at 2:56 am

    Ah! another tricky sed puzzle 🙂

    I believe this code will work for your problem:

    sed -n '/(/,/)/{:a; $!N; /)/!{$!ba}; s/.*(\([^)]*\)).*/\1/p}' file
    

    OUTPUT

    For the provided input it produced:

    1234
    567
    abc
    

    Explanation:

    • -n suppresses the regular sed output
    • /(/,/)/ is for range selection between ( and )
    • :a is for marking a label a
    • $!N means append the next line of input into the current pattern space
    • /)/! means do some actions if ) is not matched in current pattern space
    • /)/!${!ba} means go to label a if ) is not matched in current pattern space
    • s/.*(\([^)]*\)).*/\1/ means replace content between ( and ) by just the content thus stripping out parenthesis
    • \1 is for back reference of group 1 i.e. text between \( and \)
    • p is for printing the replaced content
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question that is an extension of my previous Free 3 of
this question is an extension of my previous question that you can find here:
This is an extension of the question I asked here I have a relationship
Hello every one this is extension to my previous question.Here is the link File
This is an extension of a previous question I asked. I ran into some
This is actually an extension of this question. The answers of that question did
An extension to my previous question: Text cleaning and replacement: delete \n from a
This script works as mentioned on a previous question to add @2x to all
this is an extension to a previous question I asked , today .... which
this question is an extension to a previous question i asked (and was answered).

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.