0

So I know that in order to replace something with the current date it would be

sed "s/something/`date +"%m-%d-%Y"`/" file.txt 

This would give me the date in mm-dd-YYYY But I want to be able the get the date in mm/dd/YYYY

2
  • What do you mean by proper format? What is the exact command you are running and what is the expected output supposed to look like? Please consider editing your post to include more context. Thank you! Commented Oct 9, 2019 at 19:24
  • 1
    Yes, please clarify. Do you mean m/d/y as you have in the question title? Shouldn't that be mm/dd/yy? Or perhaps mm/dd/yyyy? Please edit your question and add an example showing a specific date. Commented Oct 9, 2019 at 19:31

1 Answer 1

2

'/' has by default a special meaning for sed, so you need to either escape the '/' like this:

sed "s/something/`date +"%m\/%d\/%Y"`/" file.txt 

or use another separator for sed, like this and there is no need to escape the '/':

sed "s|something|`date +"%m/%d/%Y"`|" file.txt 
1
  • I'd still recommend you use the more modern $( ... ) construct instead of backticks. Commented Oct 9, 2019 at 20:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.