Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Formatting date time in unix using perl breaks Post 302470178 by HeadBang on Tuesday 9th of November 2010 11:22:07 AM
Old 11-09-2010
Lightbulb Formatting date time in unix using perl breaks

while read l
do
vTimeCreated=`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]' ${l}`
echo "${l} || ${vTimeCreated}" >> ${fPrefx}_Output_Files_${vDate}.txt
done < servername.txt
Using the above code to format date time for each of the filenames present in servername.txt. But it gets stuck in the perl area when huge content is there in the file. Is this a memory problem or is there any other way that we can do the formatting?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date and Time in PERL

Hi, I want to get the current date and time and subtract 1 day to get to the previous day? I see timelocal( ) and (time) etc. How do I code this in PERL to get the previous day? Thanks Nurani (2 Replies)
Discussion started by: nurani
2 Replies

2. Shell Programming and Scripting

Formatting date time in unix

while read l do vTimeCreated=`perl -e '@d=localtime ((stat(shift))); printf "%02d-%02d-%04d %02d:% 02d:%02d\n", $d,$d+1,$d+1900,$d,$d,$d' ${l}` echo "${l} || ${vTimeCreated}" >> ${fPrefx}_Output_Files_${vDate}.txt done < servername.txt Using the above code to format date time for each of the... (0 Replies)
Discussion started by: HeadBang
0 Replies

3. Shell Programming and Scripting

Creating a date (without time) in perl

I have a perl script that automatically runs on Mondays. I need to have it create a variable for last Monday's date thru that Sunday's date. example: 04-01-2011 thru 04-08-2011 Its reporting numbers for the previous week beginning with Monday and ending on Sunday. So i dont have to go in... (7 Replies)
Discussion started by: bbraml
7 Replies

4. Shell Programming and Scripting

date formatting in perl

my code: $dateformat = yyyy_mm_dd if($dateformat =~ m/yyyy/i) { print ("found"); $yyyy = strftime "%Y", localtime; print ("year is $yyyy\n"); $dateformat =~ s/yyyy/$yyyy/; print ("new date format is $dateformat\n"); } elsif($dateformat =~ m/yy/i) { print ("found"); $yy = strftime "%y",... (4 Replies)
Discussion started by: irudayaraj
4 Replies

5. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

6. Shell Programming and Scripting

PERL, Date & Time issues

Hello All, This is my first script in PERL. Hence require your help in moving further. I have a script which should populate the values for Today, Yesterday output. For which I use timeFrame as a variable to obtain the time in hrs:mm as 10:00. All I want is, I want my timeFrame to start... (4 Replies)
Discussion started by: sathyaonnuix
4 Replies

7. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

8. Emergency UNIX and Linux Support

DATE TIME formatting

can anyone one help me....to make date and time format...to following format for my file Code: DATE TIME DD- MON- YEAR 24 Hours I have a need of format like this 12-Jan-2012 in one column, then time in 24 Hours in another column....please help...me... ... (7 Replies)
Discussion started by: nex_asp
7 Replies

9. Shell Programming and Scripting

UNIX Date Formatting

Hi I have a shell variable storing DATE in YYYY-MM-DD format is there a way i extract required field say only DD Also, would be great if there is a way which could take date format as well so that code is generic for any date format eg DDMMYYYY or DD/MM/YYYY or YYYY/MM/DD etc. Thanks (4 Replies)
Discussion started by: skyineyes
4 Replies

10. UNIX for Advanced & Expert Users

Help with Formatting date in Perl

Good day. I am trying to change the output on my date so that I can get the month as a numeric value. TODAY=`perl -e 'print localtime(time()) . "\n" '` Here are the results from the above perl statement Thu Feb 11 13:16:40 2016 I am not sure of the syntax to get a date more like... (2 Replies)
Discussion started by: ziggy6
2 Replies
DateTime::Format::Natural(3pm)				User Contributed Perl Documentation			    DateTime::Format::Natural(3pm)

NAME
DateTime::Format::Natural - Create machine readable date/time with natural parsing logic SYNOPSIS
use DateTime::Format::Natural; $parser = DateTime::Format::Natural->new; $date_string = $parser->extract_datetime($extract_string); @date_strings = $parser->extract_datetime($extract_string); $dt = $parser->parse_datetime($date_string); @dt = $parser->parse_datetime_duration($date_string); if ($parser->success) { # operate on $dt/@dt, for example: printf("%02d.%02d.%4d %02d:%02d:%02d ", $dt->day, $dt->month, $dt->year, $dt->hour, $dt->min, $dt->sec); } else { warn $parser->error; } @traces = $parser->trace; DESCRIPTION
"DateTime::Format::Natural" takes a string with a human readable date/time and creates a machine readable one by applying natural parsing logic. CONSTRUCTOR
new Creates a new "DateTime::Format::Natural" object. Arguments to "new()" are options and not necessarily required. $parser = DateTime::Format::Natural->new( datetime => DateTime->new(...), lang => 'en', format => 'mm/dd/yy', prefer_future => '[0|1]', time_zone => 'floating', daytime => { morning => 06, afternoon => 13, evening => 20, }, ); o "datetime" Overrides the present now with a DateTime object provided. o "lang" Contains the language selected, currently limited to "en" (english). Defaults to '"en"'. o "format" Specifies the format of numeric dates, defaults to '"d/m/y"'. o "prefer_future" Turns ambiguous weekdays/months to their future relatives. Accepts a boolean, defaults to false. o "time_zone" The time zone to use when parsing and for output. Accepts any time zone recognized by DateTime. Defaults to 'floating'. o "daytime" An anonymous hash reference consisting of customized daytime hours, which may be selectively changed. METHODS
parse_datetime Returns a DateTime object constructed from a human readable date/time string. $dt = $parser->parse_datetime($date_string); $dt = $parser->parse_datetime(string => $date_string); o "string" The date string. parse_datetime_duration Returns one or two DateTime objects constructed from a human readable date/time string which may contain timespans/durations. Same interface and options as "parse_datetime()", but should be explicitly called in list context. @dt = $parser->parse_datetime_duration($date_string); @dt = $parser->parse_datetime_duration(string => $date_string); extract_datetime Returns parsable date/time substrings (also known as expressions) extracted from the string provided; in scalar context only the first parsable substring is returned, whereas in list context all parsable substrings are returned. Each extracted substring can then be passed to the "parse_datetime()"/ "parse_datetime_duration()" methods. $date_string = $parser->extract_datetime($extract_string); @date_strings = $parser->extract_datetime($extract_string); # or $date_string = $parser->extract_datetime(string => $extract_string); @date_strings = $parser->extract_datetime(string => $extract_string); success Returns a boolean indicating success or failure for parsing the date/time string given. error Returns the error message if the parsing did not succeed. trace Returns one or two strings with the grammar keyword for the valid expression parsed, traces of methods which were called within the Calc class and a summary how often certain units have been modified. More than one string is commonly returned for durations. Useful as a debugging aid. GRAMMAR
The grammar handling has been rewritten to be easily extendable and hence everybody is encouraged to propose sensible new additions and/or changes. See the classes "DateTime::Format::Natural::Lang::[language_code]" if you're intending to hack a bit on the grammar guts. EXAMPLES
See the classes "DateTime::Format::Natural::Lang::[language_code]" for an overview of currently valid input. BUGS &; CAVEATS "parse_datetime()"/"parse_datetime_duration()" always return one or two DateTime objects regardless whether the parse was successful or not. In case no valid expression was found or a failure occurred, an unaltered DateTime object with its initial values (most often the "current" now) is likely to be returned. It is therefore recommended to use "success()" to assert that the parse did succeed (at least, for common uses), otherwise the absence of a parse failure cannot be guaranteed. "parse_datetime()" is not capable of handling durations. CREDITS
Thanks to Tatsuhiko Miyagawa for the initial inspiration. See Miyagawa's journal entry <http://use.perl.org/~miyagawa/journal/31378> for more information. Furthermore, thanks to (in order of appearance) who have contributed valuable suggestions and patches: Clayton L. Scott Dave Rolsky CPAN Author 'SEKIMURA' mike (pulsation) Mark Stosberg Tuomas Jormola Cory Watson Urs Stotz Shawn M. Moore Andreas J. Koenig Chia-liang Kao Jonny Schulz Jesse Vincent Jason May Pat Kale Ankur Gupta Alex Bowley Elliot Shank Anirvan Chatterjee Michael Reddick Christian Brink Giovanni Pensa Andrew Sterling Hanenkamp Eric Wilhelm Kevin Field Wes Morgan Vladimir Marek Rod Taylor Tim Esselens Colm Dougan Chifung Fan Xiao Yafeng Roman Filippov SEE ALSO
dateparse, DateTime, Date::Calc, <http://datetime.perl.org> AUTHOR
Steven Schubiger <schubiger@cpan.org> LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. See <http://dev.perl.org/licenses/> perl v5.14.2 2012-05-31 DateTime::Format::Natural(3pm)
All times are GMT -4. The time now is 02:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy