Search and replace substring with an other in all the files of a folder and all its subfolders

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












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.







share|improve this question






















  • Could you please elaborate on your approach (sed, find, etcetera)?
    – maulinglawns
    Feb 1 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 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 at 19:56














up vote
1
down vote

favorite












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.







share|improve this question






















  • Could you please elaborate on your approach (sed, find, etcetera)?
    – maulinglawns
    Feb 1 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 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 at 19:56












up vote
1
down vote

favorite









up vote
1
down vote

favorite











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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








edited Feb 5 at 16:12

























asked Feb 1 at 19:27









Billal BEGUERADJ

1901210




1901210











  • Could you please elaborate on your approach (sed, find, etcetera)?
    – maulinglawns
    Feb 1 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 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 at 19:56
















  • Could you please elaborate on your approach (sed, find, etcetera)?
    – maulinglawns
    Feb 1 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 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 at 19:56















Could you please elaborate on your approach (sed, find, etcetera)?
– maulinglawns
Feb 1 at 19:36




Could you please elaborate on your approach (sed, find, etcetera)?
– maulinglawns
Feb 1 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 at 19:55




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 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 at 19:56




Also, I see you have fancy curly quotes for the sed body. Take care to use simple plain quotes there.
– glenn jackman
Feb 1 at 19:56










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










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.






share|improve this answer






















  • Thank you. But I am getting this : sed: no input files
    – Billal BEGUERADJ
    Feb 1 at 20:04










  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Feb 1 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 at 20:06










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421276%2fsearch-and-replace-substring-with-an-other-in-all-the-files-of-a-folder-and-all%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










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.






share|improve this answer






















  • Thank you. But I am getting this : sed: no input files
    – Billal BEGUERADJ
    Feb 1 at 20:04










  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Feb 1 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 at 20:06














up vote
2
down vote



accepted










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.






share|improve this answer






















  • Thank you. But I am getting this : sed: no input files
    – Billal BEGUERADJ
    Feb 1 at 20:04










  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Feb 1 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 at 20:06












up vote
2
down vote



accepted







up vote
2
down vote



accepted






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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 1 at 22:23

























answered Feb 1 at 20:01









nohillside

1,868616




1,868616











  • Thank you. But I am getting this : sed: no input files
    – Billal BEGUERADJ
    Feb 1 at 20:04










  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Feb 1 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 at 20:06
















  • Thank you. But I am getting this : sed: no input files
    – Billal BEGUERADJ
    Feb 1 at 20:04










  • @BillalBEGUERADJ Ups, sorry, try again
    – nohillside
    Feb 1 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 at 20:06















Thank you. But I am getting this : sed: no input files
– Billal BEGUERADJ
Feb 1 at 20:04




Thank you. But I am getting this : sed: no input files
– Billal BEGUERADJ
Feb 1 at 20:04












@BillalBEGUERADJ Ups, sorry, try again
– nohillside
Feb 1 at 20:05




@BillalBEGUERADJ Ups, sorry, try again
– nohillside
Feb 1 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 at 20:06




@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 at 20:06












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421276%2fsearch-and-replace-substring-with-an-other-in-all-the-files-of-a-folder-and-all%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)