Posted By: Anonymous
I have a string like
AxxBCyyyDEFzzLMN and I want to replace all the occurrences of
How can I achieve this?
I know that
echo "$string" | tr 'x' '_' | tr 'y' '_' would work, but I want to do that in one go, without using pipes.
echo "$string" | tr xyz _
would replace each occurrence of
A__BC___DEF__LMN in your example.
echo "$string" | sed -r 's/[xyz]+/_/g'
would replace repeating occurrences of
z with a single
A_BC_DEF_LMN in your example.