Description
In this example, we want to get every 4th line of a file,
i.e., 4th line, 8th line, 12th line, and so on.
|
| Raw Input
|
| Desired Output
| line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
line 13
line 14
line 15
|
| line 4
line 8
line 12
|
|
Script and Comments
Script1 [ 1] :loop
[ 2] $!{
[ 3] N
[ 4] /(\n[^\n]*){3}/!b loop
[ 5] }
[ 6] s/^([^\n]*\n){3}([^\n]*)/\2/p
[ 7] d
|
Script2 [ 1] :loop
[ 2] $!N
[ 3] s/^([^\n]*\n){3}([^\n]*)/\2/
[ 4] t
[ 5] $!b loop
[ 6] d
| |