How to extract last part of string in bash?

后端 未结 6 1549
谎友^
谎友^ 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 12:51

    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-)
    

    This uses the cut command to slice out part of the line, using a simple space as the word delimiter.

提交回复
热议问题