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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:33:46+00:00 2026-05-18T06:33:46+00:00

Based on the helpful answers I received here , I created the following script,

  • 0

Based on the helpful answers I received here, I created the following script, named it convert_image_paths.command, put it in a website folder on my mac and double-clicked it.

#!/bin/bash

# This script will operate on valid relative image paths at this level and one sub-level down, across .html and .css files.

find . -name "*.css" -o -name "*.html" -exec sed -i '' 's/\.\.\/images\//images\//g' {} ';'
find . -name "*.css" -o -name "*.html" -exec sed -i '' 's/images\//http:\/\/mycdn\.com\/images\//g' {} ';'

Unfortunately, instead of changing the relative image paths in the website to the new cdn url, it

  1. Doubled up the url: http://mycdn.com/http://mycdn.com/images/myimage.png
  2. Did that for EVERY html/css file on my machine

So my question is a) is there a tag for moron and b) how do I fix this script?

EDIT:

Let me clarify my intention:
I wanted to apply the change to all image paths with relative urls in the form

“image/{myimagepath}”

or

“../images/{myimagepath}”

  • 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-18T06:33:46+00:00Added an answer on May 18, 2026 at 6:33 am

    To answer your second question:

    b) Don’t do “find .” when you don’t know what directory the script is starting from. If you want it to start from a particular directory, tell it in the find command: find /Users/ptomblin/Shared/ ...

    As for why it doubled up the URL, it’s because you told it to.

    sed -i '' 's/images\//http:\/\/mycdn\.com\/images\//g' {}
    

    Takes every instance of the word “images/” and changed it to “http://mycdn.com/images/”, even if it already started with “http://mycdn.com/”. If that’s not what you wanted, you’re going to have to be more specific about your regexp.

    As a first attempt, I would replace BOTH lines with the following

    find /Users/ptomblin/Shared -name "*.css" -o -name "*.html" -exec sed -i '' 's@".{0,2}/?images@"http://mycdn.com/images@g' {}
    

    That will only replace images or ../images if they start with a double quote.

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

Sidebar

Related Questions

Based on a simple test I ran, I don't think it's possible to put
Based on my previous question here my new concern is how do I unit
Thanks for looking. All sincerely helpful answers are voted up. I use a password
I use two emacs (Aquamcs and text based emacs) on my Mac. I normally
Based on a few posts I've read concerning version control, it seems people think
Based on all my reading there should be one GC thread to invoke all
Based on their work, how do you distinguish a great SQL developer? Examples might
Based on the response to this question: Why does C++ have header files and
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for

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.