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.

3
  • Could you please elaborate on your approach (sed, find, etcetera)?
    – anon
    Commented Feb 1, 2018 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/@ Commented Feb 1, 2018 at 19:55
  • Also, I see you have fancy curly quotes for the sed body. Take care to use simple plain quotes there. Commented Feb 1, 2018 at 19:56

1 Answer 1

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.

3
  • Thank you. But I am getting this : sed: no input files Commented Feb 1, 2018 at 20:04
  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Commented Feb 1, 2018 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
    Commented Feb 1, 2018 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .