LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-09-2019, 04:38 AM   #1
vivekn1980
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Rep: Reputation: Disabled
Convert Time hh:mm:ss.SSS in to milliseconds


want to convert first column hh:mm:ss.SSS to milliseconds in a file.

14:00:04,909 10048 370007
14:00:05,320 10048 370007
14:00:05,462 10048 370008
14:00:05,761 10048 370008
14:00:05,809 10048 370009
14:00:05,833 10048 370009
14:00:11,320 10048 370010
14:00:11,453 10048 370010
14:00:13,097 10048 370012
14:00:13,124 10048 370012
14:00:21,102 10048 370013
14:00:21,110 10048 370013
14:00:21,371 10048 370014
14:00:21,667 10048 370014
14:00:21,711 10048 370015
14:00:21,874 10048 370015
14:00:21,920 10048 370016
14:00:21,944 10048 370016
 
Old 08-09-2019, 04:54 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,154

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
As has been pointed out in the past, wanting is one thing - what have you attempted to solve this ?.
 
Old 08-09-2019, 07:51 AM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,153
Blog Entries: 6

Rep: Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835Reputation: 1835
Some basic bash for you. You'll need to build what you want your script to do.

Code:
times="
14:00:04,909 10048 370007
14:00:05,320 10048 370007
14:00:05,462 10048 370008
14:00:05,761 10048 370008
14:00:05,809 10048 370009
14:00:05,833 10048 370009
14:00:11,320 10048 370010
14:00:11,453 10048 370010
14:00:13,097 10048 370012
14:00:13,124 10048 370012
14:00:21,102 10048 370013
14:00:21,110 10048 370013
14:00:21,371 10048 370014
14:00:21,667 10048 370014
14:00:21,711 10048 370015
14:00:21,874 10048 370015
14:00:21,920 10048 370016
14:00:21,944 10048 370016
"

a=$(echo "$times" | cut -d " " -f1)
echo "$a"

b=($(echo ${a//,/.}))
echo "$b"

for i in "${b[@]}"; do
    echo "$i"
    sleep 1
done
Code:
clock_times=(
14:00:21
14:00:27
14:00:35
14:00:44
)

for i in ${clock_times[@]}; do
    Time=$(date -d "$i" +"%s")
    echo "$Time"
done

Last edited by teckk; 08-09-2019 at 07:55 AM.
 
Old 08-09-2019, 08:04 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,768

Rep: Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984
Quote:
Originally Posted by vivekn1980 View Post
want to convert first column hh:mm:ss.SSS to milliseconds in a file.
Code:
14:00:04,909 10048 370007
14:00:05,320 10048 370007
14:00:05,462 10048 370008
14:00:05,761 10048 370008
14:00:05,809 10048 370009
14:00:05,833 10048 370009
14:00:11,320 10048 370010
14:00:11,453 10048 370010
14:00:13,097 10048 370012
14:00:13,124 10048 370012
14:00:21,102 10048 370013
14:00:21,110 10048 370013
14:00:21,371 10048 370014
14:00:21,667 10048 370014
14:00:21,711 10048 370015
14:00:21,874 10048 370015
14:00:21,920 10048 370016
14:00:21,944 10048 370016
Since we know what you want, how about showing us what you've actually DONE to try to accomplish what you want???

If you read the "Question Guidelines" (as you've been asked to do several times before), you'll see what WE want is for you to show effort, and not just ask for a handout. And this is nothing new for you, as you've been doing this same thing for YEARS:
https://www.linuxquestions.org/quest...ds-4175628798/
https://www.linuxquestions.org/quest...es-4175619644/
https://www.linuxquestions.org/quest...gs-4175618253/
https://www.linuxquestions.org/quest...at-4175628896/
 
Old 08-11-2019, 10:08 PM   #5
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,818

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by vivekn1980 View Post
want to convert first column hh:mm:ss.SSS to milliseconds in a file.

14:00:04,909 10048 370007
Hint: cut(1) and some fairly basic bash can easily do this. Do you understand what's happening in the following?
Code:
HR_AS_SEC=$(( $( echo "14:00:04,909 10048 370007" | cut -d: -f1 ) * 3600 ))
Q: Shouldn't this be in the "Programming" section?

Last edited by rnturn; 08-11-2019 at 10:09 PM. Reason: Added question.
 
Old 08-12-2019, 06:53 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,768

Rep: Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984Reputation: 7984
Quote:
Originally Posted by rnturn View Post
Hint: cut(1) and some fairly basic bash can easily do this. Do you understand what's happening in the following?
Code:
HR_AS_SEC=$(( $( echo "14:00:04,909 10048 370007" | cut -d: -f1 ) * 3600 ))
Q: Shouldn't this be in the "Programming" section?
See the OP's previous posts; the OP isn't interested in programming/working, but posts here to get a handout.
 
  


Reply

Tags
awk, bash, linux, perl



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
sss shree24985 Linux - Virtualization and Cloud 2 04-27-2012 11:06 PM
convert milliseconds to formatted data in JAVA xface66 Programming 1 12-17-2007 10:05 AM
Time in milliseconds davidguygc Programming 2 04-25-2007 06:03 PM
C/C++ API for retrieving system time in micro or milliseconds syseeker Programming 1 05-04-2006 07:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:15 PM.

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