Hello, I am asking for your help with sed. I need to remove duplicate underscores and underscores from beginning and end of string.
For example:
echo '[Lorem] ~ ipsum *dolor* sit metus !!!' | sed 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._()-]/_/g'
Produces:
_Lorem____ipsum__dolor__sit_metus____
But I need to further format this string to: Lorem_ipsum_dolor_sit_metus
In other words, remove any underscores from beginning and end of string, and reduce multiple consecutive underscore symbols into just one, preferably using another pipes.
Do you have any idea how to do that?
Thank you.