Adding lines to pattern space

view full story

http://www.unix.com – Is there any way to add lines to the pattern space of sed? I know a bit about the N flag, but am not able to use it to do what I want which is: read a file n lines at a time. If I find a match I quit else move to the next line. e.g. if I am looking for the following three lines Hello How Are you I want to start with lines 1 to 3, then move to lines 2 to 4, then 3 to 5 and so on, until I find the required lines or EOF. My query input can be more than 3 lines in size. Using this code for the above example: Code: sed -n 'N;N; s/Hello\nHow\nAre you/&/p' file1 does not (HowTos)