21Aug/090
Grep and Multiline Regular Expressions
Nothing new here: needed to go through some old log files to find something. Unfortunately, I needed to match across 2 lines specifically. I wrote up my regex, and tested it in Reggy and all was good. I tried it out in the real world but didn't get any matches. GNU Grep and Egrep don't support \n! It only searches one line at a time. Enter: pcregrep -M.
(The other catch is that the files are compressed. bzcat and zcat solve this problem.)
The entry I was looking for:
I 23:21:37:465 aaaaaaa ZzzHandler: Subscription expired for x. D 23:21:37:466 aaaaaaa ZzzHandler: Proceeding to deactivate account
So I came up with this obfuscated 'for' loop:
for i in $(find /mnt/xxxxxxx -name xxxxxxx*bz2 -type f -print)
do
echo $i; bzcat $i | \
pcregrep -M ".*ZzzHandler: Subscription expired.*\n.*Proceeding to deactivate.*"
done | tee -a /tmp/xxxxxx-archived.log