Sponsored Content
Top Forums Shell Programming and Scripting Please help formatting bash "time" variable to HH:MM:SS format Post 83430 by vgersh99 on Wednesday 14th of September 2005 06:02:23 PM
Old 09-14-2005
without going on the tangent of re-writting the function....
one way......
Code:
printf "%02d:%02d:%02d" "$HOUR" "$MINUTE" "$SECOND"

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

$0 variable using ". file" format

I need to access the script name within a korn shell script. cat tst1.sh echo Script Name: $0 when tst1.sh is run normally the script reports "Script Name: tst1.sh" However when I run the shell as ". tst1.sh" the script reports: "Script Name: -ksh" How do I access the script name when... (1 Reply)
Discussion started by: pavelmac
1 Replies

2. Shell Programming and Scripting

bash: "undefined variable" and pipe

Hi, haven't found anything about this through searching, so may be a new topic: when doing this: set -o nounset set -o errexit find . -name "*.lib" | while read library; do echo ${libary} done echo "after while" I expect the script to exit within the while loop (because of nounset and... (6 Replies)
Discussion started by: nagaidhlig
6 Replies

3. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

4. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

5. Shell Programming and Scripting

How to store the output of "time dd if= of=" in a variable

Hi All, I need to store the real seconds of the following command in a variable. How could it be done? time $(dd if=/dev/zero of=/dev/sda1 bs=512 count=2048;sync) Thanks, Amio (12 Replies)
Discussion started by: amio
12 Replies

6. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

7. Shell Programming and Scripting

Storing output of "time" command to a variable

Hi all, I am new to Linux/shell scripting having moderate knowledge. In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save... (9 Replies)
Discussion started by: happening_linux
9 Replies

8. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 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:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy