1

I know there are several questions as this one, but mine is specific:

I want to replace the substring: localhost:8000/ with https://www.begueradj.com/ in all the HTML files existing in a folder and its sub folders.

The / and // are causing me problems in this situation.

Any hints?

Edit:

The attempt I tried to work more on is the one described here.

But any other effective approach is welcome.

  • Could you please elaborate on your approach (sed, find, etcetera)? – maulinglawns Feb 1 '18 at 19:36
  • All you need to do is use different delimters for the sed s/// command: for examples@http://localhost:8000/@https://www.begueradj.com/@ – glenn jackman Feb 1 '18 at 19:55
  • Also, I see you have fancy curly quotes for the sed body. Take care to use simple plain quotes there. – glenn jackman Feb 1 '18 at 19:56
2

There are (at least) two things to improve here:

  • using for on a list of file names generated by another command tends to break in rather interesting ways if file names contain space characters or worse
  • the quotes you use in sed are odd

Try

find . -name '*.html' -print0 | 
    xargs -0 sed -i 's|localhost:8000|https://www.begueradj.com/|'

The -print0 option of find will make sure that all names passed to xargs are NUL-terminated.

  • Thank you. But I am getting this : sed: no input files – Billal Begueradj Feb 1 '18 at 20:04
  • @BillalBEGUERADJ Ups, sorry, try again – nohillside Feb 1 '18 at 20:05
  • @BillalBEGUERADJ If it still doesn't work: Does find . -name '*.html' -print return anything? If not your HTML files don't end in .html. – nohillside Feb 1 '18 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.