これは、Python のグループを使用した正規表現の一致です: http://regex101.com/r/yL3xZ5
これは簡単な例ですawk
❯ awk '/\.bundle/{ gsub(/\.bundle\/.*$/, ".bundle"); print; }' <<_EOF_
/System/Library/CoreServices/AOS.bundle/Contents/version.plist
/System/Library/CoreServices/Br.bundle/Contents/Resources/brtool
/System/Library/CoreServices/backupd.bundle/Contents/PlugIns/brtools.bundles/Contents/Version.plist
_EOF_
/System/Library/CoreServices/AOS.bundle
/System/Library/CoreServices/Br.bundle
/System/Library/CoreServices/backupd.bundle
❯
別のsed
:
❯ sed -e 's@\(\.bundle\)/.*$@\1@' <<_EOF_
/System/Library/CoreServices/AOS.bundle/Contents/version.plist
/System/Library/CoreServices/Br.bundle/Contents/Resources/brtool
/System/Library/CoreServices/backupd.bundle/Contents/PlugIns/brtools.bundles/Contents/Version.plist
_EOF_
/System/Library/CoreServices/AOS.bundle
/System/Library/CoreServices/Br.bundle
/System/Library/CoreServices/backupd.bundle
❯
純粋な別のbash
:
❯ while read line; do echo ${line/.bundle\/*/.bundle}; done <<_EOF_
/System/Library/CoreServices/AOS.bundle/Contents/version.plist
/System/Library/CoreServices/Br.bundle/Contents/Resources/brtool
/System/Library/CoreServices/backupd.bundle/Contents/PlugIns/brtools.bundles/Contents/Version.plist
_EOF_
/System/Library/CoreServices/AOS.bundle
/System/Library/CoreServices/Br.bundle
/System/Library/CoreServices/backupd.bundle
❯
そして最後に、grep
❯ grep -oP '^(.*?\.bundle)(?=/)' <<_EOF_
/System/Library/CoreServices/AOS.bundle/Contents/version.plist
/System/Library/CoreServices/Br.bundle/Contents/Resources/brtool
/System/Library/CoreServices/backupd.bundle/Contents/PlugIns/brtools.bundles/Contents/Version.plist
_EOF_
/System/Library/CoreServices/AOS.bundle
/System/Library/CoreServices/Br.bundle
/System/Library/CoreServices/backupd.bundle
❯