How to extract numbers from a string?

前端 未结 10 2106
青春惊慌失措
青春惊慌失措 2020-12-10 04:20

I have string contains a path

string=\"toto.titi.12.tata.2.abc.def\"

I want to extract only the numbers from this string.

To extrac

10条回答
  •  旧时难觅i
    2020-12-10 04:58

    Hi adding yet another way to do this using 'cut',

    echo $string | cut -d'.' -f3,5 | tr '.' ' '
    

    This gives you the following output: 12 2

提交回复
热议问题