How to realize the regular expression of path interception by shell in linux
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!