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
Post a Comment