perl -nwe "/Testwort/ and $x = $.; print if $x && ($.-$x) <= 2" test.txt