I've looked through several tutorials and a couple of StackOverflow posts, but I've not seen any examples using sed or awk which use dates. I have a text file that contains this as the first line, I need to replace the date with the current date and time via script; what is the easiest way to do this in Linux? TS: 2014-03-31 13:56:01I can use any tool available in a standard Ubuntu install such as sed or awk.
How to replace a custom date string in a text file
ubuntu;sed;awk
The simplistic approach would be to just use sed and replace the string with the correct one. So, if the current time is 2014-04-02 21:34:13 you could simply runsed 's/2014-03-31 13:56:01/2014-04-02 21:34:13/' fileSince, presumably, you want to do this dynamically, you can pass sed the result of the relevant date call instead:sed s/2014-03-31 13:56:01/$(date '+%F %T')/ fileNote the double quotes () around the sed command, those are needed for the date command to be run.