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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:42:36+00:00 2026-05-31T20:42:36+00:00

I have: %{ lorem ipsum dolor sit %{hello world}% amet}% I want: hello world

  • 0

I have:

%{ lorem ipsum dolor 
   sit %{hello
           world}%
   amet}%

I want:

 hello
   world

That is, I want to keep the inner %{...}% of any number of nesting %{...}%s that may or may not span multiple lines.

Is there a sed or awk way?

  • 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-31T20:42:37+00:00Added an answer on May 31, 2026 at 8:42 pm

    This sed command:

    sed -n -r 'H; ${g; s/([^}]|\}[^%])*%\{//; s/\}%([^%]|%[^{])*//; p}'
    

    will gather the entirety of the input into the pattern space, then remove ...%{ (taking care to ensure that the ... doesn’t contain }%) and }%... (taking care to ensure that the ... doesn’t contain %{), and then print the result. So it’s suitable for the case where you need just one block. The case with multiple blocks is trickier, but I’ll think about it further, and update this answer if I get that working well.

    Note that -r (to support Extended Regular Expressions, instead of Basic ones) is a GNU extension to sed, so if you’re using a non-GNU sed that doesn’t support it, let me know.


    Edited to add: O.K., here’s a version that supports multiple blocks:

    sed -n -r 'H; ${g; s/^([^}]|\}[^%])*%\{//; s/\}%([^%]|%[^{])*$//; s/\}%([^%]|%[^{])*([^}]|\}[^%])*%\{/\n/g; p}'
    

    It uses essentially the same approach as the previous, except that it only removes ...%{ at start-of-input and }%... at end-of-input, and that after it’s done that, it proceeds to remove all instances of }%...%{ that do not contain %{...}%, replacing them with a newline.

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

Sidebar

Related Questions

Let assume that I have some string: Lorem ipsum dolor sit amet I need
I have a string structured like that: BLOCK LIST1 Lorem ipsum dolor sit amet.
For instance, if I have a TextBlock: Lorem ipsum dolor sit amet, consectetur adipisicing
I have this The body: <body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent
I have an ordered list <ol> <li class=odd>Lorem ipsum dolor sit amet, consectetur ...</li>
Lets say we have some text: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
I have this html: <div class=box id=n5> <p class=text>Lorem ipsum dolor sit amet</p> <textarea
I have a string like this: $contenuto = Lorem ipsum dolor sit amet, consectetur
Supposing I have the following text: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
I have the following piece of HTML: <div><p>Lorem ipsum dolor sit amet, consectetur adipisicing

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.