Help with creating a text file in perl with file creation date.
Hi,
I am quite new to Perl scripting and i need to create a .TXT file using perl, with fields (A,B,C,D,E), and this text file should be named with current file creation date "XYZ_CCYYMMDD.TXT" (i.e.XYZ_2011042514:33 PM).
Can anyone who has done this, please share their expertise on this one.
1) Logical step 1. How do I get the time in perl? I guess wildly and try perldoc -f time That returns it in seconds. A start.
2) Logical step 2. How can I convert that into something I can use? Well, the 'time' function documentation suggests the localtime function and perldoc -f localtime suggests the strftime function and the POSIX module and even gives examples. time isn't needed apparently since localtime calls it implicitly unless you give it otherwise. man strftime also tells you what strings strftime needs.
3) Logical step 3. How can I open a string as a filename? The same way you open any other filename. perldoc -f open
So you get
I knew none of this by heart, I just followed the trail of instructions.
Last edited by Corona688; 04-25-2011 at 06:06 PM..
Reason: simplify out sprintf
1) Logical step 1. How do I get the time in perl? I guess wildly and try perldoc -f time That returns it in seconds. A start.
2) Logical step 2. How can I convert that into something I can use? Well, the 'time' function documentation suggests the localtime function and perldoc -f localtime suggests the strftime function and the POSIX module and even gives examples. time isn't needed apparently since localtime calls it implicitly unless you give it otherwise. man strftime also tells you what strings strftime needs.
3) Logical step 3. How can I open a string as a filename? The same way you open any other filename. perldoc -f open
So you get
I knew none of this by heart, I just followed the trail of instructions.
Answer so detailed like this is really great.
There's a Chinese proverb that reads: "授人以鱼, 不如授人以渔", which means "If you give him a fish, he'll only have a single meal, if you teach him to fish, he will feed himself for his whole life.".
You did not concatenate anything. Even if you did, you'd end up with a '<' instead of a slash between dir and filename.
open() takes a filehandle as a first argument; you are missing that. So the call you need is as follows:
The formatting of date you probably want is "%y%m%d", not %M, which would print minute, not month.
Use
; the -w switch turns warnings on; very helpful for debugging.
Hello Folks,
I have an requirement, where i need to get total count of the file based on creation date with there filename selected pattern.
Filename: MobileProtocol.20171228T154200.157115.udr
I want to get the count of files created on each day based on a pattern find.
find . -type... (7 Replies)
Hello ,
I am looking for a script to print file name and its last updated time.
FILE CREATION-TIME FILE-NAME
24/10/2017 12:34 TDR-IU-8-2017.10.24.07:40:00-2017.10.24.07:45:00
when we run l command it print the directory and the files with details like permission,... (1 Reply)
Hi guys,
I had a scenario...
1. I had to get the previous days date in yyyymmdd format
2. i had to create a file with Date inthe format yyyymmdd.txt format
both are different
thanks guys in advance.. (4 Replies)
The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Hi,
Can anyone tell me a process to find the creation date of a file in a directory.
If suppose I have a file in a directory created in 2009
-rw-r--r-- 1 xyz guest 2480 Jul 16 2009 sample.txt
The command should return the the file creation date as 16/07/2009
thanks, (2 Replies)
Hi,
I just need to know way of getting date of file when it was created.
eg i have a file abc created on 23 aug. Now i need to know date of file i.e. 23 aug. How can i get that data.
Thanks
Sarbjit (7 Replies)
I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files.
-jack (3 Replies)
Hi All,
I need to get file creation date.
I have to access one file who's name is like...
abc.log092308
and the date changes as per current date. And i am accessing this file next day. meance in above case i will access above file on 09-24-2008
Also one problem is that this file... (2 Replies)
Dear Expert,
Is there a command to do that in Unix?
In such a way that we don't need to actually "write" or
modified the content.
-- monkfan (4 Replies)