如何在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.