Linux - Server This forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
08-09-2019, 04:38 AM
#1
LQ Newbie
Registered: Nov 2017
Posts: 14
Rep:
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
08-09-2019, 04:54 AM
#2
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,154
As has been pointed out in the past, wanting is one thing - what have you attempted to solve this ?.
08-09-2019, 07:51 AM
#3
LQ Guru
Registered: Oct 2004
Distribution: Arch
Posts: 5,153
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 .
08-09-2019, 08:04 AM
#4
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,768
Quote:
Originally Posted by
vivekn1980
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/
08-11-2019, 10:08 PM
#5
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
Quote:
Originally Posted by
vivekn1980
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.
08-12-2019, 06:53 AM
#6
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,768
Quote:
Originally Posted by
rnturn
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.
All times are GMT -5. The time now is 07:15 PM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News