在bash中的给定文本中提取两个给定的不同定界符之间的文本 [英] Extract text between two given different delimiters in a given text in bash
问题描述
我有一排看起来像 hh ^ ay-pau + h @ ow
的文本,我想提取-
和 + <之间的文本/code>,在这种情况下为
pau
.这应该在bash中完成.任何帮助,将不胜感激.我想提取第一次出现的令牌之间的文本PS:我的Google搜索并没有带我去任何地方.如果这个问题已经提出,我深表歉意.
I have a line of text which looks like hh^ay-pau+h@ow
, I want to extract the text between -
and +
which in this case is pau
. This should be done in bash. Any help would be appreciated.
I want to extract the text between the first occurence of the tokens
PS: My google search didn't take me anywhere. I apologize if this question is already asked.
推荐答案
在纯 bash
中执行此操作的方法是在bash中使用参数扩展
The way to do this in pure bash
, is by using parameter expansions in bash
$ a=hh^ay-pau+h@ow
$ b=${a%%+*}
$ c=${b#*-}
$ echo $c
pau
b:删除所有内容,包括第一次 +
事件的发生和发生的时间c:删除除第一次-
出现之外的所有内容
b: remove everything including and behind the first +
occurence
c: remove everything excluding and before the first -
ocurrence
这篇关于在bash中的给定文本中提取两个给定的不同定界符之间的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!