test.txt
file:
today is date
Here are scripts I tried so far:
test.sed
file:
s/date/$(date)/
s/date/$(date '%m\ / %d \ / %y')/
Below is how I run the command line:
sed -r -f test.sed test.txt
sed -r -E -f test.sed test.txt
CodePudding user response:
sed -e "s date $(date) " test.txt
. We have to use as the separator because the date
output includes slashes.
You can't read the commands from a script file, because you need the shell to expand the $(date)
variable.
CodePudding user response:
sed -i "s/date/$(date)/g" test.txt
This will replace date string with a current date. If you want a more specific format of the date you can add arguments to the date command.