How can I shorten HH:MM:SS as much as possible?

Suppose I have the following syntax: HH:MM:SS. I want to make it as short as possible. For example, I want "00:00:30" To turn into "30". Similarly, I want "0:30:00" to turn into "30:00". How can I do this with shell commands?

Asked By: Amarakon

||

As I understand you need to remove the leading zeroes, so let’s suppose you have a file like this

00:00:30
00:01:30
00:30:00
01:30:00
30:00:00

would become

30
1:30
30:00
1:30:00
30:00:00

If that’s so, you just need to apply a sed command like this:

sed 's/^[0:]*//' file
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.