Reputation: 67
example string: /Volumes/Macintosh HD/Users/test/
I need the output to be the volume name, Macintosh HD
I've tried the following:
echo "/Volumes/testVolume/test/" | sed 's/\/Volumes\/\(.*\)\//\1/g'
but the output is: testVolume/test
Upvotes: 1
Views: 438
Reputation: 49543
This should work:
sed 's#/Volumes/\([^/]*\)/.*#\1#'
Instead of using /
to mark the search and replace expressions, you could use any other character as well. #
is a commonly used character if your search or replace expressions contain the character /
in them.
$ sed 's#/Volumes/\([^/]*\)/.*#\1#' <<< "/Volumes/Macintosh HD/Users/test/"
Macintosh HD
Upvotes: 3