Ad

I Really Need Help On How To Substitute The String "date" From The Test.txt Line With The Actual Date. I Tried Multiple Ways But No Luck

- 1 answer

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

Ad

Answer

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.

Ad
source: stackoverflow.com
Ad