I\'m writing the script that searches for lines that match some pattern. I must use sed for this script. This works fine for searching and printing matched lines:
Switch to awk.
BEGIN { ln=0 } $0 ~ m { ln+=1 print ln " " $0 next } { print $0 }
...
awk -f script.awk -v m='' < input.txt