最後の引数のみが必要で、数値の場合のみ:
echo $'For example:\nThis is counter1 1000\nthis counter2 2000\n
this counter3 is higher value 3000\ndone.\n' |
sed -ne 's/^.* \([0-9]\{1,99\}\)/\1/p'
1000
2000
3000
カウンターの番号をトラップすることもできます(したがって、を含む行のみを読み取りますcounterX
):
echo $'For example:\nThis is counter1 1000\nthis counter2 2000\n
this counter3 is higher value 3000\ndone.\n' |
sed -ne 's/^.*\(counter[0-9]\{1,99\}\) \(.* \)\{0,1\}\([0-9]\{1,99\}\)$/\1 \3/p'
counter1 1000
counter2 2000
counter3 3000
または、セパレーターを見つけるだけでも:
echo $'For example:\nThis is counter1 1000\nthis counter2 2000\n
this counter3 is higher value 3000\ndone.\n' |
sed -ne 's/^\(.*counter[0-9]\{1,99\}.*\) \([0-9]\{1,99\}\)$/\1 :: \2/p'
This is counter1 :: 1000
this counter2 :: 2000
this counter3 is higher value :: 3000
または、または...
echo $'For example:\nThis is counter1 1000\nthis counter2 2000\n
this counter3 is higher value 3000\ndone.\n' |
sed -e 's/^\(.*counter[0-9]\{1,99\}.*\) \([0-9]\{1,99\}\)$/\1 :: \2/'
For example:
This is counter1 :: 1000
this counter2 :: 2000
this counter3 is higher value :: 3000
done.