how to extract substring and numbers only using grep/sed

后端 未结 6 863
悲哀的现实
悲哀的现实 2021-02-09 14:29

I have a text file containing both text and numbers, I want to use grep to extract only the numbers I need for example, given a file as follow:

miss rate 0.21          


        
6条回答
  •  春和景丽
    2021-02-09 14:46

    Use awk instead:

    awk '/^miss rate/ { print $3 }' yourfile
    

    To do it with just grep, you need non-standard extensions like here with GNU grep using PCRE (-P) with positive lookbehind (?<=..) and match only (-o):

    grep -Po '(?<=miss rate ).*' yourfile
    

提交回复
热议问题