Get specific string

2019-07-12 12:20发布

I need to get a specific string from a bigger string:

From these Abcd1234_Tot9012_tore.dr or Abcd1234_Tot9012.tore.dr

I want to get those numbers which are between Tot and _ or . , so I should get 9012. Important thing is that the number of characters before and after these numbers may vary.

Could anyone give me a nice solution for this? Thanks in advance!

标签: bash shell sed
7条回答
时光不老,我们不散
2楼-- · 2019-07-12 12:58

Using grep you can do:

str=Abcd1234_Tot9012.tore.dr; grep -o "Tot[0-9]*" <<< $str|grep -o "[0-9]*$"

OUTPUT:

9012
查看更多
登录 后发表回答