Scenario 1: I have a variable where this string is contained:
output="abdh748mdn78##j*&#"
the special characters belong to a set called specialchars
specialchars='@#$%&*+-='
All I want for Christmas is to
1) keep one of the specialchar, discard the rest.
2) delete multiple occurrence of that one char from the string, or alternatively- just choose ONE of the special chars and discard the rest.
Scenario 2:
output="a#bdh#748m#"
Speicalchar="$char" [where $char is '#' randomly selected from set- look above]
notice there are multiple #'s
Just need to get rid of the duplicate and keep one. Then echo $output
I tried:
echo $stringout | sed 's/\([@#$%&*+-=]\)\1/\1/g'
found it on stackx but it doesn't work.
Need to keep it bash (can only use bash utils).