Sponsored Content
Top Forums Shell Programming and Scripting Bash: Data Input Verification Help! Post 91785 by Vozx on Monday 5th of December 2005 05:14:31 PM
Old 12-05-2005
Error Bash: Data Input Verification Help!

Hey guys i am trying to right script with this:

Input
Valid user input can be in the following formats:
Distance: in miles or kilometers, e.g. 100mi or 100km
Speed: miles per hour or kilometers per hour, e.g. 100m/h or 100km/h
Time: in hours and minutes, e.g. 1hr.20min, 1:20, or any integer which defaults to that number of hours, as in 3 (is 3 hours).
Any combination of the above formats can be entered on the command line and in any order.
Distance and speed can be entered as any decimal number, e.g. 50.8793mi, 78.405km/h

Problem:
I have no problem with working with speed and distance, the only problem now i am having is with time entered in this format
1hr.20min, i wanna be able to extract the numeric characters, I am guess i have to cut the variable into 2 pieces somehow, the length of the string can vary as it can be entered as 12hr.35min, so i am not sure how to do this. I wanna be able to be able to transform hour into minutesm thus if 1hr.20min is entered, i wanna use this data to get 60+20=80mins.


Is there any way i can do it using sed or awk, i am not too familiar with it so any help would be appreciated.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

input of data

Hey, i need a bit of help with a question, I am writing a script that will search a given directory for a particular type of file, which i have done, but we have to do it in such a way that we type in the directory name when we call the script. So, the script is called "demo2". At the command... (3 Replies)
Discussion started by: ljdav2
3 Replies

2. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

3. Shell Programming and Scripting

Bash user input

Hi all, I currently have a script which uses read -p for user interaction. e.g. read -p "New user? " user Is it possible to have it so if the user enters nothing and just presses return it can resort to a specified value instead? Thanks! :) (5 Replies)
Discussion started by: JayC89
5 Replies

4. Shell Programming and Scripting

Formatting input data

Hello everybody, I have a file containing some statistics regarding CPU usage. The file has this syntax : Fri Jul 16 14:27:16 EEST 2010 Cpu(s): 15.2%us, 1.4%sy, 0.0%ni, 82.3%id, 0.1%wa, 0.0%hi, 0.9%si, 0.0%st Fri Jul 16 15:02:17 EEST 2010 Cpu(s): 15.3%us, 1.4%sy, 0.0%ni, 82.3%id, ... (9 Replies)
Discussion started by: spiriad
9 Replies

5. Shell Programming and Scripting

Script for verification of Data corruption

Hi, I am from File system back ground and doing File system testing on Linux, I need script that scirpt that create the different multiple types of .txt, device file and then copy to mount point /mnt/ dir and then verify the created files and copied files, if created files and copied files are... (4 Replies)
Discussion started by: manish_tcs_hp
4 Replies

6. Shell Programming and Scripting

Help with Bash user input

I am starting to learn how to use bash and I would like the script to do the following: Asks the user for his/her name Asks the user for one number Asks the user for another number Then it adds the two numbers, Also multiply the two numbers I have the part where you get the name, and I... (3 Replies)
Discussion started by: boyboy1212
3 Replies

7. Shell Programming and Scripting

Help with reformat input data

Input file: 58227131 50087390 57339526 40578034 65348841 55614853 64363217 44178559 Desired output file: 58227131 50087390 57339526 40578034 65348841 55614853 64363217 44178559 Command that I try: (4 Replies)
Discussion started by: perl_beginner
4 Replies

8. Shell Programming and Scripting

Getting input data from 2 tables

Hello All, I have one table contains: Table1: 5 10 30 40 60 80 ... Table 2: 10 20 60 80 (7 Replies)
Discussion started by: krsnadasa
7 Replies

9. Shell Programming and Scripting

Converting variable space width data into CSV data in bash

Hi All, I was wondering how I can convert each line in an input file where fields are separated by variable width spaces into a CSV file. Below is the scenario what I am looking for. My Input data in inputfile.txt 19 15657 15685 Sr2dReader 107.88 105.51... (4 Replies)
Discussion started by: vharsha
4 Replies

10. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies
Time::Clock(3pm)					User Contributed Perl Documentation					  Time::Clock(3pm)

NAME
Time::Clock - Twenty-four hour clock object with nanosecond precision. SYNOPSIS
$t = Time::Clock->new(hour => 12, minute => 34, second => 56); print $t->as_string; # 12:34:56 $t->parse('8pm'); print "$t"; # 20:00:00 print $t->format('%I:%M %p'); # 08:00 PM $t->add(minutes => 15, nanoseconds => 123000000); print $t->as_string; # 20:15:00.123 $t->subtract(hours => 30); print $t->as_string; # 14:15:00.123 ... DESCRIPTION
A Time::Clock object is a twenty-four hour clock with nanosecond precision and wrap-around. It is a clock only; it has absolutely no concept of dates. Vagaries of date/time such as leap seconds and daylight savings time are unsupported. When a Time::Clock object hits 23:59:59.999999999 and at least one more nanosecond is added, it will wrap around to 00:00:00.000000000. This works in reverse when time is subtracted. Time::Clock objects automatically stringify to a user-definable format. CLASS METHODS
default_format FORMAT Set the default format used by the as_string method for all objects of this class. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers. Note that this method may also be called as an object method, in which case it sets the default format for the individual object only. CONSTRUCTOR
new PARAMS Constructs a new Time::Clock object based on PARAMS, where PARAMS are name/value pairs. Any object method is a valid parameter name. Example: $t = Time::Clock->new(hour => 12, minute => 34, second => 56); If a single argument is passed to new, it is equivalent to calling the parse method. That is, this: $t = Time::Clock->new('12:34:56'); is equivalent to this: $t = Time::Clock->new; $t->parse('12:34:56'); Returns the newly constructed Time::Clock object. OBJECT METHODS
add PARAMS Add the time specified by PARAMS to the clock. Valid PARAMS are: "hours INT" An integer number of hours. "minutes INT" An integer number of minutes. "seconds INT" An integer number of seconds. "nanoseconds INT" An integer number of nanoseconds. If the amount of time added is large enough, the clock will wrap around from 23:59:59.999999999 to 00:00:00.000000000 as needed. ampm AM/PM Get or set the AM/PM attribute of the clock. Valid values of AM/PM must contain the letters "AM" or "PM" (case-insensitive), optionally followed by periods. A clock whose hour is greater than 12 cannot be set to AM. Any attempt to do so will cause a fatal error. Setting a clock whose hour is less than 12 to PM will cause its hour to be increased by 12. Example: $t = Time::Clock->new('8:00'); print $t->as_string; # 08:00:00 $t->ampm('PM'); print $t->as_string; # 20:00:00 Return the string "AM" if the hour is less than 12, "PM" otherwise. as_integer_seconds Returns the integer number of seconds since 00:00:00. as_string Returns a string representation of the clock, formatted according to the clock object's default_format. default_format FORMAT Set the default format used by the as_string method for this object. Defaults to "%H:%M:%S%n". See the documentation for the format method for a complete list of format specifiers. Note that this method may also be called as a class method, in which case it sets the default format all objects of this class. format FORMAT Returns the clock value formatted according to the FORMAT string containing "%"-prefixed format specifiers. Valid format specifiers are: %H The hour as a two-digit, zero-padded integer using a 24-hour clock (range 00 to 23). %I The hour as a two-digit, zero-padded integer using a 12-hour clock (range 01 to 12). %i The hour as an integer using a 12-hour clock (range 1 to 12). %k The hour as an integer using a 24-hour clock (range 0 to 23). %M The minute as a two-digit, zero-padded integer (range 00 to 59). %n If the clock has a non-zero nanosecond value, then this format produces a decimal point followed by the fractional seconds up to and including the last non-zero digit. If no nanosecond value is defined, or if it is zero, then this format produces an empty string. Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S%n'); # 12:34:56 $t->nanosecond(0); print $t->format('%H:%M:%S%n'); # 12:34:56 $t->nanosecond(123000000); print $t->format('%H:%M:%S%n'); # 12:34:56.123 "%[1-9]n" If the clock has a defined nanosecond value, then this format produces a decimal point followed by the specified number of digits of fractional seconds (1-9). Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S%4n'); # 12:34:56 $t->nanosecond(0); print $t->format('%H:%M:%S%4n'); # 12:34:56.0000 $t->nanosecond(123000000); print $t->format('%H:%M:%S%4n'); # 12:34:56.1230 %N Nanoseconds as a nine-digit, zero-padded integer (range 000000000 to 999999999) "%[1-9]N" Fractional seconds as a one- to nine-digit, zero-padded integer. Examples: $t = Time::Clock->new('12:34:56'); print $t->format('%H:%M:%S.%4N'); # 12:34:56.0000 $t->nanosecond(123000000); print $t->format('%H:%M:%S.%6N'); # 12:34:56.123000 $t->nanosecond(123000000); print $t->format('%H:%M:%S.%2N'); # 12:34:56.12 %p Either "AM" or "PM" according to the value return by the ampm method. %P Like %p but lowercase: "am" or "pm" %S The second as a two-digit, zero-padded integer (range 00 to 61). %s The integer number of seconds since 00:00:00. %T The time in 24-hour notation (%H:%M:%S). "%%" A literal "%" character. hour INT Get or set the hour of the clock. INT must be an integer from 0 to 23. minute INT Get or set the minute of the clock. INT must be an integer from 0 to 59. nanosecond INT Get or set the nanosecond of the clock. INT must be an integer from 0 to 999999999. parse STRING Set the clock time by parsing STRING. Valid string values contain an hour with optional minutes, seconds, fractional seconds, and AM/PM string. There should be a colon (":") between hours, minutes, and seconds, and a decimal point (".") between the seconds and fractional seconds. Fractional seconds may contain up to 9 digits. The AM/PM string is case-insensitive and may have periods after each letter. The string "now" will initialize the clock object with the current (local) time. If the Time::HiRes module is installed, this time will have fractional seconds. A time value with an hour of 24 and zero minutes, seconds, and nanoseconds is also accepted by this method. Here are some examples of valid time strings: 12:34:56.123456789 12:34:56.123 PM 24:00 8:30pm 6 A.m. now second INT Get or set the second of the clock. INT must be an integer from 0 to 59. subtract PARAMS Subtract the time specified by PARAMS from the clock. Valid PARAMS are: "hours INT" An integer number of hours. "minutes INT" An integer number of minutes. "seconds INT" An integer number of seconds. "nanoseconds INT" An integer number of nanoseconds. If the amount of time subtracted is large enough, the clock will wrap around from 00:00:00.000000000 to 23:59:59.999999999 as needed. AUTHOR
John C. Siracusa (siracusa@gmail.com) LICENSE
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2010-06-04 Time::Clock(3pm)
All times are GMT -4. The time now is 01:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy