-1

I have two string like this
a=[2018:09:11-18:37:06:376476]
b=[2018:09:11-18:37:06:376446]
I want two string like
a= 20180911183706376476
b= 20180911183706376446

Can Anyone please help me out?

1

If your shell supports "//" substitutions in variables you can use

a=${a//[]:[-]/}

(notice that "-" should be last and "]" should be first in the [...] range expression.

If not, you can use something like this:

set_trim(){ local IFS=[:-]; v=$1; set -- $2; IFS=; eval "$v=$*"; }
set_trim a "$a"
set_trim b "$b"

or, with sed (less efficient since it has to start an external program):

a=`echo $a | sed 's/[]:[-]//g'`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.