The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read/writte/input data in file. dorek Shell Programming and Scripting 0 06-22-2006 08:31 AM
Reading in data sets into arrays from an input file. sidamin810 Shell Programming and Scripting 5 07-06-2005 08:54 AM
verification? sheranjem UNIX for Dummies Questions & Answers 3 06-06-2005 02:08 PM
input of data ljdav2 Shell Programming and Scripting 3 09-05-2004 11:01 PM
Bash overwrites data on screen!! brain_processin Shell Programming and Scripting 4 03-13-2002 07:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-05-2005
Vozx Vozx is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 12
Exclamation 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.
  #2 (permalink)  
Old 12-06-2005
grasper grasper is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 45
Try:-

mins=$(echo $time|sed -n 's/.*[^0-9]\([0-9][0-9]*\).*/\1/p’)

hrs=$(echo $time|sed -n 's/\([0-9][0-9]*\)[^0-9]*.*/\1/p')

I think that should give you the hours and minutes whatever format the time is entered in.

Cheers
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:00 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0