使用bash的字符串整数提取 [英] Extract integer from string using bash

查看:82
本文介绍了使用bash的字符串整数提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在这里找到解决办法,但不能;给出的字符串喜欢

I tried to find the solution here but could not; given strings like

ABC3
DFGSS34
CVBB3

我怎么提取整数,所以我得到

how do I extract the integers so I get

3
34
3

...

推荐答案

只是一个简单的sed命令将做的工作:

Just a simple sed command will do the job:

sed 's/[^0-9]//g' file.txt

输出

3
34
3

这篇关于使用bash的字符串整数提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆