sed: print only matching group

前端 未结 5 1331
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 02:26

I want to grab the last two numbers (one int, one float; followed by optional whitespace) and print only them.

Example:

foo bar  bla 1 2 3         


        
5条回答
  •  借酒劲吻你
    2020-12-23 03:18

    grep is the right tool for extracting.

    using your example and your regex:

    kent$  echo 'foo bar  bla 1 2 3.4'|grep -o '[0-9][0-9]*[\ \t][0-9.]*[\ \t]*$'
    2 3.4
    

提交回复
热议问题