Shell – Remove last / of path string using sed

sedshell

I'm trying to use sed to replace just the last / in the following directory structure, but I'm not able to succeed with this. Any suggestions?

Input is /tmp/ABC/Dirs/, output should be /tmp/ABC/Dirs

echo " /tmp/ABC/Dirs/"  | sed -r "s/\/(?:[a-zA-Z0-9])/g"

Best Answer

I was the one who answered the question first with my s/\/$// comment.

Other people had time to contribute much fuller answers that day.

SO today -a few days later- I post a redundant answer, because I want the "Peer Pressure" Bronze award gone from the list.

sed -e s./$..g   # You can golf the quotes and the "\" here

So please, good folks, please downvote this time until -3 :)

Related Question