sed extracting group of digits

前端 未结 5 1679
终归单人心
终归单人心 2021-02-18 15:18

I have tried to extract a number as given below but nothing is printed on screen:

echo \"This is an example: 65 apples\" | sed -n  \'s/.*\\([0-9]*\\) apples/\\1/         


        
5条回答
  •  眼角桃花
    2021-02-18 16:14

    A simple way for extracting all numbers from a string

    echo "1213 test 456 test 789" | grep -P -o "\d+"
    

    And the result:

    1213
    456
    789
    

提交回复
热议问题