string - Linux BASH - Replace multiple occurrences of a char, omitting single occurrence -


experts: bit hard explain. need replace multiple occurrences of character other character (i know accomplished using sed or tr) tricky part need keep single occurrences of character are.

example, replacing multiple occurrences of "_" ";":

this have: "this___________is_a____string"

this need: "this;is_a;string"

is there way this?

thanks in advance

well sed below:

echo "this___________is_a____string" | sed 's/_\{2,\}/;/g' 

output:

this;is_a;string 

the trivial part being {2,} quantifier means match _ 2 or longer, ie. leave single _ unchanged.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -