I need to replace a string in html sed is not working











up vote
0
down vote

favorite












Here is the code in the shell script I have used



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


The code is trying to print HTML tags inside AWK command



nawk 'BEGIN{
FS=","
print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the"
print "xyxx that meet the criteria for submission</p>"
}
END{
print "<p>Regards,<br>Support Team</p></BODY></HTML>"
}
'









share|improve this question









New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • You should state your desired result and the actual result.
    – RalfFriedl
    2 days ago










  • do u want to replace xyxx with the value of date1 or just as $date1?
    – msp9011
    2 days ago










  • I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
    – RAJESH A S
    2 days ago










  • use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
    – RoVo
    2 days ago












  • Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
    – RoVo
    2 days ago















up vote
0
down vote

favorite












Here is the code in the shell script I have used



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


The code is trying to print HTML tags inside AWK command



nawk 'BEGIN{
FS=","
print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the"
print "xyxx that meet the criteria for submission</p>"
}
END{
print "<p>Regards,<br>Support Team</p></BODY></HTML>"
}
'









share|improve this question









New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • You should state your desired result and the actual result.
    – RalfFriedl
    2 days ago










  • do u want to replace xyxx with the value of date1 or just as $date1?
    – msp9011
    2 days ago










  • I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
    – RAJESH A S
    2 days ago










  • use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
    – RoVo
    2 days ago












  • Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
    – RoVo
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Here is the code in the shell script I have used



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


The code is trying to print HTML tags inside AWK command



nawk 'BEGIN{
FS=","
print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the"
print "xyxx that meet the criteria for submission</p>"
}
END{
print "<p>Regards,<br>Support Team</p></BODY></HTML>"
}
'









share|improve this question









New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Here is the code in the shell script I have used



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


The code is trying to print HTML tags inside AWK command



nawk 'BEGIN{
FS=","
print "<HTML>""<HEAD>""<p>Hi All,<br><br>There are no cases closed on the"
print "xyxx that meet the criteria for submission</p>"
}
END{
print "<p>Regards,<br>Support Team</p></BODY></HTML>"
}
'






awk sed aix html






share|improve this question









New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Jeff Schaller

36.3k952120




36.3k952120






New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









RAJESH A S

11




11




New contributor




RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






RAJESH A S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • You should state your desired result and the actual result.
    – RalfFriedl
    2 days ago










  • do u want to replace xyxx with the value of date1 or just as $date1?
    – msp9011
    2 days ago










  • I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
    – RAJESH A S
    2 days ago










  • use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
    – RoVo
    2 days ago












  • Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
    – RoVo
    2 days ago


















  • You should state your desired result and the actual result.
    – RalfFriedl
    2 days ago










  • do u want to replace xyxx with the value of date1 or just as $date1?
    – msp9011
    2 days ago










  • I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
    – RAJESH A S
    2 days ago










  • use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
    – RoVo
    2 days ago












  • Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
    – RoVo
    2 days ago
















You should state your desired result and the actual result.
– RalfFriedl
2 days ago




You should state your desired result and the actual result.
– RalfFriedl
2 days ago












do u want to replace xyxx with the value of date1 or just as $date1?
– msp9011
2 days ago




do u want to replace xyxx with the value of date1 or just as $date1?
– msp9011
2 days ago












I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
– RAJESH A S
2 days ago




I need to replace xyxx with value of date1 inside the file or can I use print command itself inside awk
– RAJESH A S
2 days ago












use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
– RoVo
2 days ago






use sed -i to edit files in place. Your command will not work, because redirections are done first. So you'll be ending up with an empty file.
– RoVo
2 days ago














Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
– RoVo
2 days ago




Also, if you need variable replacement, you need to put the sed command in double quotes for bash to expand the variables.
– RoVo
2 days ago










1 Answer
1






active

oldest

votes

















up vote
1
down vote













In this command,



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


the redirection happens first! So the shell opens /u001/Scripts/abc.html for writing and empties it. Then the sed command runs, but the input file is empty, so no output either.



As the comments suggest, you should use:



sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html 


which will




  • create a backup file with extension .bak and overwrite the original file (-i.bak)

  • and use the variable value of $date1, because it's put in double quotes, unlike the rest of the sed expression.






share|improve this answer








New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
    – RAJESH A S
    yesterday










  • make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
    – RoVo
    yesterday











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: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






RAJESH A S is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483132%2fi-need-to-replace-a-string-in-html-sed-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













In this command,



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


the redirection happens first! So the shell opens /u001/Scripts/abc.html for writing and empties it. Then the sed command runs, but the input file is empty, so no output either.



As the comments suggest, you should use:



sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html 


which will




  • create a backup file with extension .bak and overwrite the original file (-i.bak)

  • and use the variable value of $date1, because it's put in double quotes, unlike the rest of the sed expression.






share|improve this answer








New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
    – RAJESH A S
    yesterday










  • make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
    – RoVo
    yesterday















up vote
1
down vote













In this command,



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


the redirection happens first! So the shell opens /u001/Scripts/abc.html for writing and empties it. Then the sed command runs, but the input file is empty, so no output either.



As the comments suggest, you should use:



sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html 


which will




  • create a backup file with extension .bak and overwrite the original file (-i.bak)

  • and use the variable value of $date1, because it's put in double quotes, unlike the rest of the sed expression.






share|improve this answer








New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
    – RAJESH A S
    yesterday










  • make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
    – RoVo
    yesterday













up vote
1
down vote










up vote
1
down vote









In this command,



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


the redirection happens first! So the shell opens /u001/Scripts/abc.html for writing and empties it. Then the sed command runs, but the input file is empty, so no output either.



As the comments suggest, you should use:



sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html 


which will




  • create a backup file with extension .bak and overwrite the original file (-i.bak)

  • and use the variable value of $date1, because it's put in double quotes, unlike the rest of the sed expression.






share|improve this answer








New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









In this command,



sed 's/xyxx/$date1/' /u001/Scripts/abc.html > /u001/Scripts/abc.html 


the redirection happens first! So the shell opens /u001/Scripts/abc.html for writing and empties it. Then the sed command runs, but the input file is empty, so no output either.



As the comments suggest, you should use:



sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html 


which will




  • create a backup file with extension .bak and overwrite the original file (-i.bak)

  • and use the variable value of $date1, because it's put in double quotes, unlike the rest of the sed expression.







share|improve this answer








New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 2 days ago









Arcticooling

584




584




New contributor




Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Arcticooling is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
    – RAJESH A S
    yesterday










  • make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
    – RoVo
    yesterday


















  • I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
    – RAJESH A S
    yesterday










  • make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
    – RoVo
    yesterday
















I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
– RAJESH A S
yesterday




I am unable to get the output on the mentioned command above sed -i.bak 's/xyxx/'"$date1"'/' /u001/Scripts/abc.html
– RAJESH A S
yesterday












make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
– RoVo
yesterday




make sure that $date1 does not contain characters that are interpreted by sed, e.g. a slash or an @ will cause problems.
– RoVo
yesterday










RAJESH A S is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















RAJESH A S is a new contributor. Be nice, and check out our Code of Conduct.













RAJESH A S is a new contributor. Be nice, and check out our Code of Conduct.












RAJESH A S is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483132%2fi-need-to-replace-a-string-in-html-sed-is-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt