Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列の例:/Volumes/Macintosh HD/Users/test/
/Volumes/Macintosh HD/Users/test/
出力をボリューム名にする必要があります。Macintosh HD
Macintosh HD
私は次のことを試しました:
echo "/Volumes/testVolume/test/" | sed 's/\/Volumes\/\(.*\)\//\1/g'
しかし、出力は次のとおりです。testVolume/test
testVolume/test
これはうまくいくはずです:
sed 's#/Volumes/\([^/]*\)/.*#\1#'
を使用して検索式と置換式をマークする代わりに、/他の文字を使用することもできます。#は、検索式または置換式に文字が含まれている場合に一般的に使用される文字です/。
/
#
$ sed 's#/Volumes/\([^/]*\)/.*#\1#' <<< "/Volumes/Macintosh HD/Users/test/" Macintosh HD