Please try the following commands:
echo "(After Sweet Memories) Play Born To Lose Again" | tr '(' '-' | tr ')' '-' | tr ' ' '-'
-After-Sweet-Memories--Play-Born-To-Lose-Again
(notice the double --
)
I'm unable to modify the command and pass a (null) value instead i have to pass another -
see this example and this error:
echo "(After Sweet Memories) Play Born To Lose Again" | tr '(' '' | tr ')' '' | tr ' ' '-'
tr: tr: when not truncating set1, string2 must be non-emptywhen not truncating set1, string2 must be non-empty
You can use "tr -d" to just remove chars. Is this the solution you are searching for?
echo "(After Sweet Memories) Play Born To Lose Again" | tr -d '(' | tr -d ')' | tr ' ' '-'
After-Sweet-Memories-Play-Born-To-Lose-Again
A tr
solution has been provided, but tr
requires you run multiple instances in a pipeline. You can do it all in one process with sed
.
echo "(After Sweet Memories) Play Born To Lose Again" | sed 's/ /-/g; s/[()]//g;'
After-Sweet-Memories-Play-Born-To-Lose-Again
You can even lose the echo
(though that's hardly an issue...)
sed 's/ /-/g; s/[()]//g;' <<< "(After Sweet Memories) Play Born To Lose Again"
After-Sweet-Memories-Play-Born-To-Lose-Again
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With