how to get timestamp of a file in a perl script


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users how to get timestamp of a file in a perl script
# 1  
Old 04-01-2008
Question how to get timestamp of a file in a perl script

I have seen this posting here:

perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d[3],$d[4]+1,$d[5]+1900,$d[2],$d[1],$d[0]' file1.txt

I need to use it inside a perl script. Can anybody please help me out.
# 2  
Old 04-01-2008
Quote:
Originally Posted by biswajeet.beher
I have seen this posting here:

perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d[3],$d[4]+1,$d[5]+1900,$d[2],$d[1],$d[0]' file1.txt

I need to use it inside a perl script. Can anybody please help me out.
Sure. Cut and paste it into your text editor you're using to write the Perl script. Let us know how it turns out.

ShawnMilo
# 3  
Old 04-01-2008
I copied the whole stamenet along with "perl -e"

Thanks, I copied the whole statement into my perl script , but it is giving synatax error:

syntax error at compare_forms2.pl line 27, near "perl -e "

Here is the code i used in my per script:

perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d[3],$d[4]+1,$d[5]+1900,$d[2],$d[1],$d[0]
'$ddt_dir_prod[1];

Where $ddt_dir_prod[1] contains a valid file.
# 4  
Old 04-01-2008
Either you're joking, or you have no business writing code today. Please pick up a basic Perl book or read a Web tutorial and let us know when you can write a simple Perl script and understand what it does.

Sincerely,
ShawnMilo
# 5  
Old 04-01-2008
I apologize for the rudeness of my comment. I know that I sometimes come off more harshly than I mean to, and I also thought that my first post was funny.

But in all seriousness, you don't seem to understand some very basic things, and it wouldn't really help you if we gave you the answers because you wouldn't be able to apply them. Also, you haven't even said what you're trying to accomplish. That makes it nearly impossible for anyone to help you anyway.

If you get anything even half-working, post it and someone may be able to help you fix it. But, as I said, it doesn't appear that you know enough Perl (or maybe programming in general) to be making this attempt without further study.

ShawnMilo
# 6  
Old 04-01-2008
it's ok...i am new to perl

ya u r right. I am very new to this field..as you said have to learn the basic concepts first.Any way thank you very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script Closest Timestamp (LOG FILE)

Hi All, I need something where I could take the date from FILE1 and in this case the date is Thu Sep 10 13:48:42 EDT 2015 and I need it to match the closest PREVIOUS date in the log file FILE2 this means in this specific case it would be Thu Sep 10 2015 13:35:28. I only need the closest... (3 Replies)
Discussion started by: roberto999
3 Replies

2. Shell Programming and Scripting

Timestamp conversion in PERL

Hi, I have a file as below I need to overwrite the 2 nd column alone to numeric format like "06122011030414012345" as per the timestamp value output file should be the microseconds can be neglected if required. Any help will be appreciated. Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

3. Programming

Sort the files on their name and then the timestamp using Perl

Hi All, I am new to Perl. I have a scenario to code. In a folder I have number of files and they will start with P01 or P02 or P03 and so on..I have to sort them on name first and then on time stamp. Ex. File name timestamp P01_file1.txt 1PM P02_file1.txt 1AM P01_file2.txt 2PM... (12 Replies)
Discussion started by: unankix
12 Replies

4. Shell Programming and Scripting

How to get the timestamp for file using shell script

I am writing a script to move the executable from one node to another and take the backup of the existing one. For that I want to fetch the timestamp of file using shell script. Could anyone help? (2 Replies)
Discussion started by: gagankinra
2 Replies

5. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

6. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

7. UNIX for Advanced & Expert Users

Automated SCP script passing password to preserve source file timestamp

Hi My requirement is i want to copy files from remote server to the local server and also i need to preserve the timestamp of the remote file. By using scp -p , it is working fine in the interactive call but it is not preserving he file timestamp when i use it in the non interactive scp call... (1 Reply)
Discussion started by: skumar75
1 Replies

8. Shell Programming and Scripting

[Perl] Timestamp conversion

Hi, I have searched, read and tried, but no luck. I have this code: #!/bin/perl -w #-d use strict; use POSIX qw(strftime); my $getprpw_list="/usr/lbin/getprpw -l"; my $host = "nbsol151"; my $user = "genadmin"; my %uid; my %spwchg; my %upwchg; my %slogint; (2 Replies)
Discussion started by: ejdv
2 Replies

9. Shell Programming and Scripting

How to get timestamp of file into ksh script

Hi - I need to run a script via cron which will do some ldapsearches. One of the search parameters will be modifytimestamp. I need to have some way of storing the timestamp of the last time the script ran, and then retrieving that timestamp to use in the ldapsearch command (i.e.... (5 Replies)
Discussion started by: sniper57
5 Replies

10. Linux

SED/AWK Script to clear log file using timestamp?

I have a log file on our system which fills up with lines that have been timestamped, as follows.... 03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:07:003]... (2 Replies)
Discussion started by: davesimm
2 Replies
Login or Register to Ask a Question