This question already has an answer here:
do you have any idea how to add some end line like
"=========================================================================================="
after every match
tail -f error.log -n 2000 | grep -B 10 -A 25 'Exception:'
this command prints all Exceptions log but i likes to see one seperator line for each exception log.
I prefer
sed
for text manipulation:You posted a command that doesn't do what you want and described it's output, but you didn't tell us what you DO want so this is a guess but maybe it'll be useful. It prints the 2 lines before and 3 lines after some regexp:
For people like myself who have a 'very old' grep that doesn't include the
--group-separator
option, the following seems to be an acceptable workaround.Noticing that
grep
(my version, 2.5.1) does produce a "small, default" separator between groups (--
), you can easily replace that string with a string of your choice:This does replace the
--
with============
Obviously you can modify this to your liking. If you have the option of using
--group-separator
(@sudo_O's answer) that is obviously preferable.EDIT reading the comments below the question, I realize that when @starrify updated his comment (which I had not noticed before) his comment essentially pointed directly to this solution - so I feel I own him a tip of the hat...
You want the following option:
Demo: