Description
In the following example, we want to extract all strings matched
[0-9]+(a sequence of digits),
and print them one per line.
Note that Script3 is the most efficient one.
|
| Raw Input
|
| Desired Output
| number 123 number 45 number
number 6 another 7890 more 13579
no numbers in this line
2468086 last 1248163264 no more
|
| 123
45
6
7890
13579
2468086
1248163264
|
|
Script and Comments
Script1 [ 1] s/^[^0-9]*([0-9]+)/\1\n/
[ 2] /\n/!d
[ 3] P
[ 4] D
| |
Script2 [ 1] s/^[^0-9]*([0-9]+)/\1\n/
[ 2] /\n/P
[ 3] D
|
Script3 [ 1] s/[0-9]+/\n&\n/g
[ 2] s/[^\n]*\n([0-9]*\n)/\1/g
[ 3] s/\n[^\n]*$//p
[ 4] d
| |
|