Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell: Sed -i.bak to rename file by appending current date

I have sed statement to replace few contents in my file. It is taking a backup copu with the name file.bak before replacing the content.

sed -i.bak -r "s#^(.*/abc_def_APP/).*(/application1\.war.*)#\1$version1/$version2\2#" /path/file

But I want the file to be backed up with current date. something like file.071913

How can I get it?

like image 307
Jill448 Avatar asked Dec 25 '22 23:12

Jill448


1 Answers

Since we have date "+%m%d%y" that returns MMDDYY (month day year):

$ date "+%m%d%y"
071913

What about saying sed -i.$(this command) so you have the following?

sed -i.$(date "+%m%d%y") -r .... file
like image 83
fedorqui 'SO stop harming' Avatar answered Jan 14 '23 07:01

fedorqui 'SO stop harming'