0

I have an output of a command/script as below...

63-19:48:47

I want a script to read it and print it as 63days 19hours 48mins 47seconds.

If it is just 19:48:47, then I want the same script to print as 19hours 48mins 47seconds.

Is there a way to split the output and assign it to different variables to achieve the abouve results or thru some other emans?...Please help me out.

2
  • Which shell are your using? bash? Commented Jan 29, 2014 at 9:55
  • SHELL=/bin/ksh. Please let me know if that helps. Commented Jan 29, 2014 at 11:23

1 Answer 1

3
echo 63-19:48:47 | tr ':-' ' ' |read a b c d

Or if number of parameters is not strict (3 or 4):

set `echo 63-19:48:47 | tr ':-' ' '`
if [ -z "$4" ]
then
  day="$1"
  shift
fi
hour="$1"
min="$2"
sec="$3"
Sign up to request clarification or add additional context in comments.

4 Comments

tr: Not a recognized flag: : tr: 0653-712 The combination of options and String parameters is not legal. Usage: tr [ -[c|C] | -[c|C]ds | -[c|C]s | -ds | -s ] [-A] String1 String2 tr { -[c|C]d | -[c|C]s | -d | -s } [-A] String1
I am getting the above output
I used the same as above. My output was for above
I'm sorry! I've made a typo. Please see my edit and note that now it is :-, not -:. I'm sorry once again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.