[clug] Perl one-liner: Fix 'From id at addr' lines in email (maildir) files

steve jenkin sjenkin at canb.auug.org.au
Thu Sep 9 01:33:21 MDT 2010

[STFW didn't turn up a quick answer, hence something to seed the cloud
for others.]

Here's a perl one-liner to do a simple fixup of email files where the
beginning line:

 'From id at addr  Wed Jul 25 06:06:08 2001'
has been munged to be invalid:
'From id at addr  Wed Jul 25 06:06:08 2001'.

Because there are too many fields in the line (3 addr not 1), tools like
mutt and mailx die...

Started here:

Ended here after some help from 's2p' to get the grep expr for
match/replace right.

Inplace editing, no copy kept (dangerous):
 perl -pi -e 's/^From (.*) at /From ${1}\@/' *

Save the old file in .bak:
 perl -pi.bak -e 's/^From (.*) at /From ${1}\@/' *

I had to do some manual cleanup afterwards as well, there were lines of
normal text in the files starting with 'From '...

As a complete discursion, I wanted to add line numbers into a file.
 perl -ni.bak -e 'chomp();printf "%05d:%s\n", $., $_;' t

or non-perl:
 nl -s: -w5 -n rz t


PS: I can't see these notes being of use in harvesting email addresses.
Don't do anything special or hard.

Steve Jenkin, Info Tech, Systems and Design Specialist.
0412 786 915 (+61 412 786 915)
PO Box 48, Kippax ACT 2615, AUSTRALIA

sjenkin at canb.auug.org.au http://members.tip.net.au/~sjenkin

More information about the linux mailing list