LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-10-2009, 08:45 PM   #1
kram66
LQ Newbie
 
Registered: May 2009
Posts: 1

Rep: Reputation: 0
Grab time from string


I've developed a script that gathers the time from a string using the cut function, however one of the problems is that the location of the time can change, therefore I can't use the cut function.

rw-rw-rw- some text might go here 10:50 AM some other text might go here

I need to grab the 10:40 AM from the string. What is the best way to do this?
 
Old 05-10-2009, 09:23 PM   #2
kellinwood
Member
 
Registered: Jan 2006
Location: Culver City, California
Distribution: Fedora
Posts: 64

Rep: Reputation: 21
Regular expression matching can be used to solve this problem....

echo "rw-rw-rw- some text might go here 10:50 AM some other text might go here" | grep -Po '\d\d:\d\d (AM|PM)'
10:50 AM

time=`echo "rw-rw-rw- some text might go here 10:50 AM some other text might go here" | grep -Po '\d\d:\d\d (AM|PM)'`
echo $time
10:50 AM
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mplayer : grab (or at least display) remaining time in track? lumix Linux - Software 3 09-14-2010 05:49 PM
Get time as a string HarryBoy Programming 3 08-01-2008 01:34 AM
Help with a UNIX script: Need to grab information based on time from a file dba_guy Programming 13 05-28-2008 10:01 PM
Converting time from string to long format Deepak Inbasekaran Programming 6 07-21-2006 05:00 PM
how to grab multiple files at the same time in SFTP? HiOctane21 Programming 1 05-02-2004 01:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration