sed: print only matching group

前端 未结 5 1329
伪装坚强ぢ
伪装坚强ぢ 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:21

    The cut command is designed for this exact situation. It will "cut" on any delimiter and then you can specify which chunks should be output.

    For instance: echo "foo bar bla 1 2 3.4" | cut -d " " -f 6-7

    Will result in output of: 2 3.4

    -d sets the delimiter

    -f selects the range of 'fields' to output, in this case, it's the 6th through 7th chunks of the original string. You can also specify the range as a list, such as 6,7.

提交回复
热议问题