[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Bash Script Help



Almut Behrens wrote:

On Mon, May 23, 2005 at 04:17:44PM -0500, Colin Ingram wrote:
(...)

this creates a file that looks like this:
00:00.000, 3.24557e+007
00:02.510, 3.23482e+007
00:05.007, 3.24578e+007
00:07.507, 2.77091e+007
---snip---

I now need to covert the "elapse time" column from the string format "hours:min:sec" to a column containing just seconds. I am unsure how to do this. Can I use command substitution in a sed substitute command?

You could pipe the output of your script through the following perl
command:

 ... | perl -pe 's/^(\d+):(\d+):(\d+)/$1*60**2 + $2*60 + $3/e'

in case the time string represents "hours:min:sec".
If it's "min:sec.msec" (looks like it to me...), then it'd be

its actually "[hours]:min:sec" (the secs have ms precision). I assume I can make the first subexpression match zero or one time. In that situation if the first subexpression doesn't match does $1=null?

 ... | perl -pe 's/^(\d+):([\d.]+)/$1*60 + $2/e'

The s///e option requests command subtitution, where the value can be
any perl code, the result of which will be the replacement string.
I'll look into this some more.  Thanks for the suggestion



Reply to: