Perl:Script to append date and time stamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl:Script to append date and time stamp
# 1  
Old 01-23-2014
Perl:Script to append date and time stamp

Help with Perl script :

I have a web.xml file with a line

Code:
<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

Code:
<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
# 2  
Old 01-23-2014
Try:
Code:
perl -i -spe 's!</display-name>!.$d$&!' -- -d=`date +"%m_%d_%Y_%H_%M_%S"` path/to/web.xml

# 3  
Old 01-24-2014
Code:
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. Smilie
# 4  
Old 01-24-2014
You are using Windows CMD, which doesn't actually have proper quoting. Do you have any better shells available?
# 5  
Old 01-24-2014
This should work if you're indeed on Windows. Slight modification to bartus11's good suggestion. Tested on a Windows 7 box:

Code:
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>

# 6  
Old 01-24-2014
@bartus11 :

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

Code:
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
Code:
<displayname>some_text_here.d_H_S</displayname>

Smilie

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

Figured it out with some googling ..

Code:
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

Last edited by Franklin52; 01-25-2014 at 04:09 AM.. Reason: adding code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script | Parse log file after a given date and time stamp

I am developing one script which will take log file name, output file name, date, hour and minute as an argument and based on these inputs, the script will scan and capture all the error(s) that have been triggered from a given time. Example: script should capture all the error after 13:50 on Jan... (2 Replies)
Discussion started by: ROMA3
2 Replies

2. Shell Programming and Scripting

Files with date and time stamp

Hi Folks, Need a clarification on files with date and time stamp. Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS". Now i need to check for this file and if it is available then i need to do some task to the file. I tried... (6 Replies)
Discussion started by: jayadanabalan
6 Replies

3. Emergency UNIX and Linux Support

How to append date and time stamp before the two extensions?

hi, i have some file names. my file names are as follows: c_abc_new.txt.xls c_def.txt.xls i want to append date time stamp in the below manner. c_abc_new_YYYYMMDD_HH24MISS.txt.xls c_def_YYYYMMDD_HH24MISS.txt.xls check the two input file names, they differ in naming. the 1st file name... (9 Replies)
Discussion started by: Little
9 Replies

4. Shell Programming and Scripting

append date time stamp via ftp script

I have searched several thread and not found my solution, so I am posting a new qustion. I have a very simple script on an AIX server that FTPs 2 files to a MS FTP server. These 2 files are created on the AIX server every hour, with a static name. I need to FTP the files to the MS server, but... (1 Reply)
Discussion started by: sknisely
1 Replies

5. Shell Programming and Scripting

time stamp perl script error out of range 1..31

Hi, while running the perl script i am getting this error message , Day '' out of range 1..31 at rsty.sh line 44 what do iam missing in the script, any suggestion #!/usr/bin/perl use Time::Local; my $wday = $ARGV; my $month = $ARGV; # convert the month shortname into 0-11 number if... (4 Replies)
Discussion started by: saha
4 Replies

6. UNIX for Advanced & Expert Users

rsync - date/time stamp

Hi, We are using RSYNC for syncing remote directories and working great. Our requirement is to have the destination files with date/time stamp of when they're copied on to the destination server, NOT the date/time stamps of source files/directories. As RSYNC, by default, preserving the same... (4 Replies)
Discussion started by: prvnrk
4 Replies

7. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies

8. Shell Programming and Scripting

Insert Time and Date Stamp

I have a directory with following files in it ABC.000.DAT ABC.001.DAT ABC.002.DAT ABC.003.DAT I want to insert time and date stamp in file names like ABC.000.YYYYMMDDHHMM.DAT I able to insert the time and date stamp at the end of filename Kindly help (1 Reply)
Discussion started by: aajmani
1 Replies

9. Shell Programming and Scripting

Date Time Stamp

I'm trying to write a script that checks the DTS of a file the compares it to the current time. If greater that 60 mins has gone by and the file has not been written to alert. So far I have the time pulled from the file but I dont know how to compare the times against a 60 min difference. ... (2 Replies)
Discussion started by: jarich
2 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question