If I want to find a line in file and display the surrounding context I use
If I also want to limit output to the first few occurrences I add
The problem is that
grep just stops reading the file after last occurrence, not displaying the context after that line, e.g.
grep -C 1 -m 2 -n "string" filename
123:line before 124:string - first time 125:line after -- -- 789:line before 790:string - second time
791 will not be displayed. This is probably the right behaviour (stop reading immediately after search is done), but how can I display full context anyway?