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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:12:09+00:00 2026-05-23T22:12:09+00:00

What would be the sed command for mac shell scripting that would replace all

  • 0

What would be the sed command for mac shell scripting that would replace all iterations of string “fox” with the entire string content of myFile.txt.

myFile.txt would be html content with line breaks and all kinds of characters. An example would be

    </div>
  </div>
  <br>
  <div id="container2">
    <div class="question" onclick="javascript:show('answer2')";>

Thanks!

EDIT 1

This is my actual code:

sed -i.bkp  '/Q/{
s/Q//g
r /Users/ericbrotto/Desktop/question.txt
}' $file

When I run it I get:

sed in place editing only works for regular files. 

And in my files the Q is replaced by a ton of chinese characters (!). Bizarre!

  • 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-23T22:12:11+00:00Added an answer on May 23, 2026 at 10:12 pm

    You can use the r command. When you find a ‘fox’ in the input…

    /fox/{
    

    …replace it with the empty string…

        s/fox//g
    

    …and read the input file:

        r f.html
    }
    

    If you have a file such as:

    $ cat file.txt
    the
    quick
    brown
    fox
    jumps
    over
    the lazy dog
    fox dog
    

    the result is:

    $ sed '/fox/{
        s/fox//g
        r f.html
    }' file.txt
    the
    quick
    brown
    
        </div>
      </div>
      <br>
      <div id="container2">
        <div class="question" onclick="javascript:show('answer2')";>
    jumps
    over
    the lazy dog
     dog
        </div>
      </div>
      <br>
      <div id="container2">
        <div class="question" onclick="javascript:show('answer2')";>
    

    EDIT: to alter the file being processed, just pass the -i flag to sed:

    sed -i '/fox/{
        s/fox//g
        r f.html
    }' file.txt
    

    Some sed versions (such as my own one) require you to pass an extension to the -i flag, which will be the extension of a backup file with the old content of the file:

    sed -i.bkp '/fox/{
        s/fox//g
        r f.html
    }' file.txt
    

    And here is the same thing as a one liner, which is also compatible with Makefile

    sed -i -e '/fox/{r f.html' -e 'd}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like one sed command to accomplish the following: $ sed s'/:/ /g'
I wrote a piped shell command that has multiple pipes in it that works
I did a word replace with sed via Putty and i see that the
Would having a nice little feature that makes it quicker to write code like
Would it suppose any difference regarding overhead to write an import loading all the
Would it be possible to write a class that is virtually indistinguishable from an
There are many things that all programmers should know, but I am particularly interested
I would like to get an AND -operator to the following Vim command :command!
I'm trying to use the linux sed command to append a path element to
I want a sed script that I can use for 1) finding instances, and

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.