- or download this
# $y is <C>yet</C> set for the second read, @u is <C>unwanted</C> <P>
...
33333
44444<P>
- or download this
perl -lnE "BEGIN{$r=shift;$r=qr/$r/;$n=shift@ARGV;push @ARGV,$ARGV[0]}
+eof&&!$y?$y=close ARGV:/$r/&&!$y?push @u,$.-$n..$.+$n:$y&&!($.~~@u)?s
+ay:0" XXXXX 1 next-and-previous.txt
11111
...
perl -lnE "BEGIN{$r=shift;$r=qr/$r/;$n=shift;push @ARGV,$ARGV[0]}eof&&
+!$y?$y=close ARGV:/$r/&&!$y?push @u,$.-$n..$.+$n:$y&&!($.~~@u)?say:0"
+ XXXXX 2 next-and-previous.txt
22222
- or download this
perl -slnE "BEGIN{$r=qr/$r/;push @ARGV,$ARGV[0]}eof&&!$y?$y=close ARGV
+:/$r&&!$y?push@u,$.-$n..$.+$n:$y&&!($.~~@u)?say:0"
-- -r=XXXXX -n=1 next-and-previous.txt
...
33333
44444