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

  • Home
  • SEARCH
  • 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 8658411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:45:39+00:00 2026-06-12T15:45:39+00:00

We have a process which can use a file containing sed commands to alter

  • 0

We have a process which can use a file containing sed commands to alter piped input.

I need to replace a placeholder in the input with a variable value, e.g. in a single -e type of command I can run;

$ echo "Today is XX" | sed -e "s/XX/$(date +%F)/"
Today is 2012-10-11

However I can only specify the sed aspects in a file (and then point the process at the file), E.g. a file called replacements.sed might contain;

s/XX/Thursday/

So obviously;

$ echo "Today is XX" | sed -f replacements.sed
Today is Thursday

If I want to use an environment variable or shell value, though, I can’t find a way to make it expand, e.g. if replacements.txt contains;

s/XX/$(date +%F)/

Then;

$ echo "Today is XX" | sed -f replacements.sed
Today is $(date +%F)

Including double quotes in the text of the file just prints the double quotes.

Does anyone know a way to be able to use variables in a sed file?

  • 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-12T15:45:41+00:00Added an answer on June 12, 2026 at 3:45 pm

    This might work for you (GNU sed):

    cat <<\! > replacements.sed
    /XX/{s//'"$(date +%F)"'/;s/.*/echo '&'/e}
    !
    echo "Today is XX" | sed -f replacements.sed
    

    If you don’t have GNU sed, try:

    cat <<\! > replacements.sed
    /XX/{
        s//'"$(date +%F)"'/
        s/.*/echo '&'/
    }
    !
    echo "Today is XX" | sed -f replacements.sed | sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the method Process(IEnumerable<Record> records) which can take UP TO but NO MORE
I need to process an input file, and copy its content (line by ilne)
In PowerBuilder, to locally deploy the application, you can use the .srj file which
I have a process which has a notify method which receives as a parameter
I have a process which gives me continuously output in Screen. I want to
I have a process which iterates through a bunch of ActiveRecord models, does some
I have a process x which uses system C function to start ntpd daemon.
We have a feed process which runs every day of the year. As part
I have a C++ process which has a thread that needs to send floats
I have a Spring Batch process which has following kind of code. <step id=step1

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.