LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-20-2014, 09:36 PM   #1
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 101

Rep: Reputation: 4
formatting text


Hello all,

I was wondering if anyone knew how to format all of the different time formats that I have in a text file. I want all of the times imported in a MySQL table. As a result all of these different time formats need to be converted to the default TIME (HH:MM:SS) format in MySQL.
Attached Files
File Type: txt runtime.txt (7.7 KB, 25 views)
 
Old 05-21-2014, 01:03 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,802

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
first replace comma, dot is generally used.
next, you can parse easily hours and minutes
calculate seconds and round
format to HH:MM:SS

perl, awk or similar tools can do this task, but I think you can solve it using only bash builtins.
 
Old 05-21-2014, 01:36 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
do you need to do this only once or do you want to automate the process?
 
Old 05-21-2014, 07:42 AM   #4
lonesoac0
Member
 
Registered: Jan 2010
Distribution: Ubuntu
Posts: 101

Original Poster
Rep: Reputation: 4
I would like to automate the process if I could.
 
Old 05-21-2014, 07:44 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,802

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Why not? The steps are there, you need to choose your preferred language and implement... (and test)
 
Old 05-21-2014, 01:19 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
you have to build a parser that transforms the times, then go through the file line-by-line and write to a new file. the logic of the entries seems pretty stable, dots and commas are used only for breaking down minutes.
most probably someone has already implemented something like it as part of a bigger project, but my experience is that starting from scratch will be less time consuming than trying to adapt code from elsewhere...

people often seem to choose sed for tasks like this.
 
Old 05-22-2014, 07:21 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As above, pick a language start programming
Having had a quick look at the list, it's pretty irregular formats, so I'd use Perl: YMMV
 
  


Reply

Tags
formating, regex, vi



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Fields and Text Being Displayed from Text File devUnix Programming 23 02-28-2011 02:17 PM
[SOLVED] formatting text vikas027 Programming 12 10-20-2008 11:52 PM
C Text Formatting oulevon Programming 6 02-10-2006 09:39 PM
How do I keep the formatting out of a text document? joshknape Linux - Software 12 09-09-2005 07:32 PM
TCL/TK Formatting text liguorir Linux - Software 0 05-02-2004 09:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:40 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