Description
Get the N-th matched line.
In the following,
we want to get the 5-th line containing 'match'.
|
| Raw Input
|
| Desired Output
| ......
match-1
match-2...match-2....
.....
match-3...
.....
.....
match-4...
.....
match-5...
match-6...
|
| match-5...
|
|
Script and Comments
Script1 [ 1] /match/!d
[ 2] H
[ 3] x
[ 4] /^(\n[^\n]*){5}/!{
[ 5] x
[ 6] d
[ 7] }
[ 8] s/^.*\n//
[ 9] q
| |
Script2 [ 1] /match/!d
[ 2] H
[ 3] x
[ 4] s/^([^\n]*\n){5}//
[ 5] /\n/!q
[ 6] x
[ 7] d
| |