庆典 - 从字符串中提取数 [英] bash - extract number from string
本文介绍了庆典 - 从字符串中提取数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从字符串中提取一些可变长度的。
I want to extract a number of variable length from a string.
的字符串看起来是这样的:
The string looks like this:
used_memory:1775220696
我想Ø在一个变量的1775220696的一部分。有很多关于这个问题,但我无法找到一个适合我的需求的解决方案。
I would like o have the '1775220696' part in a variable. There are a lot of questions about this, but I could not find a solution that suits my needs.
先谢谢了。
推荐答案
您可以使用剪切
:
my_val=$(echo "used_memory:1775220696" | cut -d':' -f2)
或者也 AWK
:
my_val=$(echo "used_memory:1775220696" | awk -F':' '{print $2}')
这篇关于庆典 - 从字符串中提取数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文