I want to have the value of
date + "%Y%m%d"
to be piped as the substituting word in sed
cat template.html | sed s/\\@\\@DATENUMBER\\@\\@/date +"%Y%m%d"/g
But this isn't allowed. How do I extract the value of the date and pipe it correctly?
I want to have the value of
date + "%Y%m%d"
to be piped as the substituting word in sed
cat template.html | sed s/\\@\\@DATENUMBER\\@\\@/date +"%Y%m%d"/g
But this isn't allowed. How do I extract the value of the date and pipe it correctly?
Try:
sed "s/@@DATENUMBER@@/$(date +"%Y%m%d")/g" template.html
Notes:
There is no need for cat because sed will take a file name as an argument.
If the text that you want to replace looks like @@DATENUMBER@@, then there is no need for all those backslashes: @ is neither a shell-active character nor a sed-active character and does not need to be escaped.
If you want the date command to be executed, you have to use command substitution, $(...).
The whole of the sed s command should be in quotes so that the shell does not do word splitting on it.