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.
Use the -A argument to grep to specify how many lines beyond the match to output. And use -B n to grep lines before the match. And -C in grep to add lines both above and below the match!
Using the grep Command. If we use the option '-A1', grep will output the matched line and the line after it.
For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for the number of lines after the match. If you want the same number of lines before and after you can use -C num . This will show 3 lines before and 3 lines after.
grep's -A 1 option will give you one line after; -B 1 will give you one line before; and -C 1 combines both to give you one line both before and after, -1 does the same.
You want the following option:
--group-separator=SEP
Use SEP as a group separator. By default SEP is double hyphen (--).
Demo:
$ cat file
before
exception 1
after
foo
bar
before
exception 2
after
$ grep -A 1 -B 1 --group-separator======================== exception file
before
exception 1
after
=======================
before
exception 2
after
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With