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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:42:07+00:00 2026-06-11T23:42:07+00:00

I would like to replace all { } on a certain line with [

  • 0

I would like to replace all { } on a certain line with [ ], but unfortunately I am only able to match the last occurrence of the regexp.

I have a config file which has structure as follows:

entry {
    id      123456789
    desc    This is a description of {foo} and was added by {bar}
    trigger 987654321
}

I have the following sed, of which is able to replace the last match ‘bar’ but not ‘foo’:

sed s'/\(desc.*\){\(.*\)}/\1\[\2\]/g' < filename

I anchor this search to the line containing ‘desc’ as I would hate for it to replace the delimiting braces of each ‘entry’ block.

For the life of me I am unable to figure out how to replace all of the occurrences.

Any help is appreciated – have been learning all day and unable to read any more tutorials for fear that my corneas might crack.

Thanks!

  • 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-11T23:42:08+00:00Added an answer on June 11, 2026 at 11:42 pm

    Try the following:

    sed '/desc/ s/{\([^}]*\)}/[\1]/g' filename
    

    The search and replace in the above command will only be done for lines that match the regex /desc/, however I don’t think this is actually necessary because sed processes text a line at a time, so even without this you wouldn’t be replacing braces on the ‘entry’ block. This means that you could probably simplify this to the following:

    sed 's/{\([^}]*\)}/[\1]/g' filename
    

    Instead of .* inside of the capturing group [^}]* is used which will match everything except closing braces, that way you won’t match from the first opening to the last closing.

    Also, you can just provide the file name as the final argument to sed instead of using input redirection.

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

Sidebar

Related Questions

I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all
I would like to be able to have a pattern that matches only expressions
I would like to replace all occurences of strings like: {something1} {someother2} {thing3} but
Using vim I would like to replace all characters up to a certain one
In a text, I would like to replace all occurrences of $word by [$word]($word)
I am looking for the best br2nl function. I would like to replace all
I would like to search and replace all occurrences outside of <>. I can
I would like to take a field and replace all characters that are not
Basically, I would like to decode a given HTML document, and replace all special
sum( int(i.replace(',',''))if re.search('\d',i)!=None for i in list) I would like to sum all elements

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.