Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Cool, I actually didn't know that [abc] would make a or b or c... Most of the time I use ranges like [a-z] and [0-9]... So in the end the \\ is more about windows users and sed -E 's/[\/][^\/]*$//g' would be enough to make it work on Linux... With the limitations that you mentioned though. Thanks! Commented Apr 15, 2022 at 5:19
  • 1
    @raylight Even sed 's/[/][^/]*$//' should do. Commented Apr 15, 2022 at 5:21
  • I see... I'd be more like the case in sed 's/\/[^/]*\/[^/]*$//g'. Going back two folders now... That ends up being better than using dirname multiple times in my opinion... Commented Apr 15, 2022 at 5:39
  • 1
    If you want to mangle Unix pathnames, consider basename(1), dirname(1), or perhaps the builtins to your shell. Commented Apr 15, 2022 at 19:17