string - Bash- getting rid of duplicate chars from a set in output -
scenario 1: have variable string contained:
output="abdh748mdn78##j*&#" the special characters belong set called specialchars
specialchars='@#$%&*+-=' all want christmas
1) maintain 1 of specialchar, discard rest.
2) delete multiple occurrence of 1 char string, or alternatively- take 1 of special chars , discard rest.
scenario 2:
output="a#bdh#748m#" speicalchar="$char" [where $char '#' randomly selected set- above] notice there multiple #'s
just need rid of duplicate , maintain one. echo $output
i tried:
echo $stringout | sed 's/\([@#$%&*+-=]\)\1/\1/g' found on stackx doesn't work.
need maintain bash (can utilize bash utils).
string bash shell sed duplicate-removal
No comments:
Post a Comment