There's a ton of text-munging tools, if you want to preserve the colorization you have to tell them what to look for, here's one that doesn't rely on the specific count but just strips everything between the diff
and the @@
.
(If you're new to regexes they can be daunting but the barf code below parses out as \x1b[^m]*m
matches a color escape in otherwise plain text, the ^()*
around it says any number of what's in the parens at the start of a line, so ^(\x1b[^m]*m)*
matches any number of color escapes at the start of a line.)
git log --color=always -p \
| sed -E '/^(\x1b[^m]*m)*diff/,/^(\x1b[^m]*m)*@@/ {//!d}'
Which stripping the color processing from would make the code more and the results less pleasant to read,
git log -p --color=never -p \
| sed -E '/^diff/,/^@@/ {//!d}'
In sed
, //
says "search again for the last pattern you searched for", and in a pattern-bounded range on the first line that starts out as the first-line pattern, on all subsequent lines starts out as the last-line pattern. So //!d
as a pattern range command deletes everything that's not the first or last lines.