This one-liner is really simple, but it illustrates some of the cool things you can do with perl as you approach the limitations of bash.
The purpose of this one-liner is to start with an email address and then pull out the log messages that relate to the email event.
grep <something> /var/log/exim4/mainlog | perl -e 'while(<>){/ ([0-9a-zA-Z-]*) =>/; print `grep $1 /var/log/exim4/mainlog`;}'
The first part is a simple grep where we are searching a file for the occurrence of a given string. We then pipe the output into perl. Once in perl we use a “while” loop operating on standard input(STDIN or <STDIN> or <>). We use a regular expression to capture the transaction id of the email which we then use in another grep to print the entire email’s logs to the screen. This makes more sense when the code is rearranged like so.
while(<STDIN>)
{
/ ([0-9a-zA-Z-]*) =>/;
print `grep $1 /var/log/exim4/mainlog`;
}