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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:56:02+00:00 2026-06-12T00:56:02+00:00

I’d like to replace some numbers in a file with the result of a

  • 0

I’d like to replace some numbers in a file with the result of a calculation using the found number, and like to use sed on MacOSX. I’ve tried a lot of variants and now know I have to use -E to use modern instead of basic regular expression.

Some examples:

echo "bla 18934750 + wwv_flow_id.offset bla" | sed s/\ +\ wwv_flow_id.offset/blabla/

gives

bla 18934750blabla bla

So without the -E, it finds and replaces fixed text.
But with the -E, it doesn’t:

echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E s/\ +\ wwv_flow_id.offset/blabla/

gives

bla 18934750 + wwv_flow_id.offset bla

In other words: no match and no change in the text.
The ultimate goal is to find the number that precedes the fixed text ” + wwv_flow_id.offset” and use that number and subtract a fixed number (say 750) from it, so the end result becomes:

bla 18934000 + wwv_flow_id.offset bla

And for that I need at least back references, which also don’t work like I expected, because

echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E s/\([0-9]+\)\ /\1/

gives

bla 1+ wwv_flow_id.offset bla

I hope some regex guru can help me out here.

UPDATE

With the help of ruakh, this is what I’ve got now:

echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E 's/([0-9]+) \+ wwv_flow_id.offset/(\1-750) \+ wwv_flow_id.offset/'

which returns:

bla (18934750-750) + wwv_flow_id.offset bla

The bonus question now is, how to turn this into

bla 18934000 + wwv_flow_id.offset bla

UPDATE 2

I managed to achieve my desired result by combining sed with awk, like this:

echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E 's/([0-9]+)([ ]*)\+([ ]*)wwv_flow_id.offset/~\1~\2\+\3wwv_flow_id.offset/' | awk -F~ '{print $1 $2-750 $3}'

(I know for sure there are no ~ tokens on the original 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-06-12T00:56:03+00:00Added an answer on June 12, 2026 at 12:56 am

    In “modern” regexes, + has a special meaning — it means “one or more” (just like how * means “zero or more”) — so to match an actual plus sign, you need to use \+. Since you apparently prefer not to wrap your sed-script in quotes, you would write it as \\+:

    echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E s/\ \\+\ wwv_flow_id.offset/blabla/
    

    though I think it will make your life easier if you abandon that preference, and write:

    echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E 's/ \+ wwv_flow_id.offset/blabla/'
    

    Quoting your argument will also address your back-reference issue, whereby Bash is translating \1 to 1:

    echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E 's/([0-9]+) /\1/'
    

    though if you still prefer to stick with your non-quoted-sed-script style, you could write \\1:

    echo "bla 18934750 + wwv_flow_id.offset bla" | sed -E s/\([0-9]+\)\ /\\1/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.