Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the regular expression of path interception by shell in linux

Shulou Source: shulou.com Published: 2022-06-03 18:43:23 11月12日 Update

Editor to share with you how to achieve path interception of regular expressions in shell in linux. I hope you will get something after reading this article. Let's discuss it together.

File=/dir1/dir2/dir3/my.file.txt

We can replace it with ${} to get different values:

${file#*/}: remove the first / and the string to the left: dir1/dir2/dir3/my.file.txt

${file##*/}: remove the last / and the string to the left: my.file.txt

${file#*.}: take off the first one. And the string to the left: file.txt

${file##*.}: remove the last one. And the string to the left: txt

${file%/*}: remove the last line / and the string to the right: / dir1/dir2/dir3

${file%%/*}: remove the first / and the string to the right: (null)

${file%.*}: remove the last one. And the string to the right: / dir1/dir2/dir3/my.file

${file%%.*}: take off the first one. And the string to the right: / dir1/dir2/dir3/my

After reading this article, I believe you have a certain understanding of "how to achieve path interception regular expressions in shell in linux". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Right regular expression path article different finished more knowledge industry information information channel channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Docker Shulou Tech Info OPPO Reno