sed - how to remove trailing slashes

I know you can remove trialing slashes using:

#echo "/tmp/one/two/three////" | sed "s,/$,,"
/tmp/one/two/three///

But I want to know how to make it remove all trialing flashes in the front, and in the start, so the end result is:

tmp/one/two/three

Anyone have any idea how to do this with sed?

Thanks!

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 01:11 PM ---------- Previous update was at 01:09 PM ----------

echo "/tmp/one/two/three////"  | sed 's#/*$##;s#^/*##'
sed -e "s,/\+$,," -e "s,^/\+,,"
1 Like
sed s'/\[ //'

Am I close? Thanks in advance!

yes, you're - depending on what your input and the desired output could be.

echo '[foo bar[]]' | sed s'/\[//g'

Almost, remove the space after the bracket:

sed s'/\[//'

Regards

I should have realised that :frowning:

Thank you vgersh99 and Franklin52 :slight_smile: