Description
In the following example:
- We want to extract the third through the
seventh matches of [0-9]+.
- Besides, the following script can be adapted to extract discrete number of
matches.
For example, extract the third, the seventh, and the eleventh matches.
|
| Raw Input
| First 111802 Second 22235 Third 33392
Fourth 44410984 Fifth 555432583
Sixth 6667181 Seventh 7778297 Eighth 888133
Ninth 9997 Tenth 00086 Eleventh 11123401
Twelfth 12229999
|
|
| Desired Output
| 33392
44410984
555432583
6667181
7778297
|
|
Script and Comments
Script1 [ 1] s/[0-9]+/\n&/
[ 2] /\n/!d
[ 3] s/^[^\n]*\n//
[ 4] G
[ 5] s/$/\n/
[ 6] h
[ 7] s/^[^\n]*\n//
[ 8] x
[ 9] s/[0-9]+/&\n/
[10] /^[^\n]*\n[^\n]*\n\n{3,7}$/P
[11] s/\n*$//
[12] D
| |
Script2 [ 1] s/[0-9]+/\n&/
[ 2] /\n/!d
[ 3] s/^[^\n]*\n//
[ 4] G
[ 5] s/$/\n/
[ 6] h
[ 7] s/^[^\n]*\n//
[ 8] x
[ 9] s/[0-9]+/&\n/
[10] /^[^\n]*\n[^\n]*\n\n{7}$/{
[11] s/\n.*$//
[12] q
[13] }
[14] /^[^\n]*\n[^\n]*\n\n{3,6}$/P
[15] s/\n*$//
[16] D
| |
Script3 [ 1] s/[0-9]+/\n&/
[ 2] /\n/!d
[ 3] G
[ 4] s/^[^\n]*\n(.*)/\1\n/
[ 5] h
[ 6] s/^[^\n]*\n//
[ 7] x
[ 8] s/[0-9]+/&\n/
[ 9] s/^([^\n]*)\n[^\n]*\n\n{7}$/\1/
[10] /\n/!q
[11] /^[^\n]*\n[^\n]*\n\n{3,6}$/P
[12] s/\n*$//
[13] D
| |