如何去除导致在bash节 [英] How to removing leading section in bash
本文介绍了如何去除导致在bash节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能删除部分字符串达到一定的角色?
How can I remove parts of a string up to a certain character?
例)如果我有字符串 testFile.txt.1
和 testFile.txt.12345
哪有我删除 1
和 12345
?
Ex.) If I have the string testFile.txt.1
and testFile.txt.12345
how can I remove the 1
and 12345
?
编辑:我的意思是,除去和扔掉一个字符串的第一部分达到一定的角色,并保持它的结束
I meant to remove and throw away the first part of a string up to a certain character and keep the end of it.
推荐答案
仅仅使用bash的设施
using just bash facilities
$ s=testFile.txt.1
$ echo ${s%.*}
testFile.txt
$ s=testFile.txt.12345
$ echo ${s%.*}
testFile.txt
前导零之前删除
$ echo ${s#*.}
txt.12345
其他的方法,你可以使用IFS分割你串起来。
Other method, you can split your string up using IFS
$ s=testFile.txt.12345
$ IFS="."
$ set -- $s
$ echo $1
testFile
$ echo $2
txt
$ echo $3
12345
这篇关于如何去除导致在bash节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文