如何在bash中提取字符串的最后一部分? [英] How to extract last part of string in bash?
本文介绍了如何在bash中提取字符串的最后一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个变量:
A="Some variable has value abc.123"
我需要提取该值,即abc.123
. bash有可能吗?
I need to extract this value i.e abc.123
. Is this possible in bash?
推荐答案
您如何知道该值从哪里开始?如果它始终是第5和第6个字,则可以使用例如:
How do you know where the value begins? If it's always the 5th and 6th words, you could use e.g.:
B=$(echo $A | cut -d ' ' -f 5-)
这使用cut
命令将行的一部分切出,并使用一个简单的空格作为单词定界符.
This uses the cut
command to slice out part of the line, using a simple space as the word delimiter.
这篇关于如何在bash中提取字符串的最后一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文