How to extract last part of string in bash?

后端 未结 6 1544
谎友^
谎友^ 2020-12-28 12:39

I have this variable:

A="Some variable has value abc.123"

I need to extract this value i.e abc.123. Is this possible i

6条回答
  •  情深已故
    2020-12-28 13:11

    As pointed out by Zedfoxus here. A very clean method that works on all Unix-based systems. Besides, you don't need to know the exact position of the substring.

    A="Some variable has value abc.123"
    
    echo $A | rev | cut -d ' ' -f 1 | rev                                                                                            
    
    # abc.123
    

提交回复
热议问题