开发者

RegEx Assistance. Bash on OSX

开发者 https://www.devze.com 2023-04-12 10:07 出处:网络
This is probably a simple question but I\'m new to bash and OSX. I would like a regex expression that returns a string between two periods followed by the word LSSharedFileList开发者_高级运维.

This is probably a simple question but I'm new to bash and OSX. I would like a regex expression that returns a string between two periods followed by the word LSSharedFileList开发者_高级运维.

For example "org.videolan.vlc.LSSharedFileList.plist.lockfile" would return only "vlc".

The beginning and end of the string may change but I will only ever need the text between the periods preceding "LSSharedFileList".

Any help would be much appreciated. Thanks.


$ echo org.videolan.vlc.LSSharedFileList.plist.lockfile | sed -e 's/.*\.\(..*\)\.LSSharedFileList.*/\1/'
vlc


Here's how you can do this using bash parameter expansion:

FOO="org.videolan.vlc.LSSharedFileList.plist.lockfile"

# Strip off ".LSSharedFileList" and whatever follows
BAR=${FOO%.LSSharedFileList*}

# Strip off everything from the beginning up to the first period
BAR=${BAR##*.}

echo $BAR
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号