Friday, January 11, 2008

ASSP and grep Part 2

I just used this monstrosity because I needed to get the email addresses of things that I knew whitelisted but I wanted to remove and populate the redlist.

grep "whitelist addition" maillog.txt | grep "my expression" | cut -d \> -f 1 | cut 33- > rlist

What does it do?

  1. It finds all the "whitelist additions" in maillog.txt
  2. For all of those, it searches for "my expression" to further limit what I'm searching
  3. It then cuts the resulting line off at the > delimiter.
  4. Then, it grabs the email address after position 33
  5. and dumps it into rlist

I probably *should* have used awk to do this, but I didn't have it, and this is the ugly way to get the email list that I wanted. Arguably, I could have used cut -d \< -f 2 instead of the cut 33- but there you have it.

Edited to add: actually, the latter option is better/more flexible. I'd suggest that in the future.

Further edited to add:
grep "whitelist addition" maillog.txt | grep -v ""
This shows me all whitelists that my server made that were based upon bounces (contact-forwards, usually), not from true outbound from local users.

No comments:

Blog Archive