I'm trying to parse a standard diff of some sql files to return only the delete sections. I have been using grep with the after context (-A) which almost works (only because I know that delete sections will all be very short). e.g.
diff $$_$1.sql $$_$2.sql|egrep -A3 "[01234567889][01234567889]d[01234567889][0123456789]"
I am thinking that with AWK, I could tell it start at (the above regex) and stop at the first line starting with a digit or the first line ending with a —
I have played around a bit, but can't seem to find the right syntax to do this. Can this be done with AWK? or is there another tool I should use?
Best Answer
Please give us an example if it is not what you want:
EDIT
Although you've accepted my answer but I still want to edit my post to share with you a regex that can help you solve your problem thoroughly.
sed
allows you excluding the matching lines withb
- branch command:but with this regex,
sed
also remove the REGEX1. So, Lookahead appears in my mind:but it not works because the
sed
,awk
,grep
uses the POSIX RE flavor which doesn't support negative lookahead. You should try with Python, Perl, Ruby, ...