user3153014
user3153014

Reputation: 318

how to convert hh:mm:ss into hhmmss for single data input using shell

I have time in format hh:mm:ss in a variable and I need to change it in hhmmss format for processing using shell script. eg. time=12:12:10 and I want it in variable new_time in format 121210. Please suggest command.

Upvotes: 0

Views: 86

Answers (3)

suhas
suhas

Reputation: 733

you can use sed command

m='12:12:10'
echo "$m"|sed 's/\://g'

output will be

121210

Upvotes: 0

anubhava
anubhava

Reputation: 785256

Using tr:

t='12:12:10'
echo "$t" | tr -d ':'
121210

Upvotes: 0

F. Hauri  - Give Up GitHub
F. Hauri - Give Up GitHub

Reputation: 70822

bash simply:

time=12:12:10

echo ${time//:}
121210

Upvotes: 1

Related Questions