Home > Blockchain >  I really need help on how to substitute the string "date" from the test.txt line with the
I really need help on how to substitute the string "date" from the test.txt line with the

Time:10-01

test.txt file:

today is date

Here are scripts I tried so far:

test.sed file:

  1. s/date/$(date)/

  2. s/date/$(date '%m\ / %d \ / %y')/

Below is how I run the command line:

  1. sed -r -f test.sed test.txt

  2. 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.

  • Related