I want grep to look for two patterns and output different lines of context for each match: for example, when it matches โwarningโ, it prints 1 line before and 1 line after - and when it matches โerrorโ, output 1 line before and 2 lines after; so i tried this:
$ echo -ne "1\n2\n3\n4\nwarning\n5\n6\n7\n8\nerror\n9\n10\n11\n12\n" | grep -e "warning" -A 1 -B 1 -e "error" -B 1 -A 2 4 warning 5 6 -- 8 error 9 10
... however, unfortunately, it does not work - apparently, only the final arguments -B / -A implemented for all templates.
Does anyone have an idea how to achieve a separate context for each search template?
sdaau source share