Perl:Script to append date and time stamp

Help with Perl script :

I have a web.xml file with a line

<display-name>some_text_here</display-name>

Need to append the current date and time stamp to the string and save the XML file
Something like

<display-name>some_text_here._01_23_2014_03_56_33</display-name>

-->Finally want to pass the path to the XML file as argument to the perl script

Script.pl path/to/web.xml

Thanks

Try:

perl -i -spe 's!</display-name>!.$d$&!' -- -d=`date +"%m_%d_%Y_%H_%M_%S"` path/to/web.xml
C:\>perl -i -spe 's!</display-name>!.$d$&!' -- -d=`date +"%m_%d_%Y_%H_%M_%S"` we
b.xml

The system cannot find the file specified.
'!'' is not recognized as an internal or external command,
operable program or batch file. :frowning:

You are using Windows CMD, which doesn't actually have proper quoting. Do you have any better shells available?

This should work if you're indeed on Windows. Slight modification to bartus11's good suggestion. Tested on a Windows 7 box:

C:\>type c:\temp\web.xml
<display-name>some_text_here</display-name>

C:\>perl -MPOSIX -i.BKUP -spe "$tm=strftime(qq{%m_%d_%Y_%H_%M_%S}, localtime);s#<\/display-name>#.$tm$&#" c:\temp\web.xml

C:\>type c:\temp\web.xml
<display-name>some_text_here.01_24_2014_11_38_53</display-name>

@bartus11 :

I am trying to run this by putting in a shell script on cygwin. This is the error I get

Can't do inplace edit without backup.

@in2nix4life

This works when I run it on CMD but when I put it in a batch script I get the result as

<displayname>some_text_here.d_H_S</displayname>

:frowning:

---------- Post updated at 01:34 PM ---------- Previous update was at 01:10 PM ----------

Figured it out with some googling ..

perl -i.bak -spe 's!</display-name>!.$d$&!' -- -d=`date +"%m_%d_%Y_%H_%M_%S"` path/to/web.xml

---------- Post updated at 01:34 PM ---------- Previous update was at 01:34 PM ----------

Thanks everybody