[Cialug] Text file munging

Zachary Kotlarek zach at kotlarek.com
Thu Jun 18 14:32:27 CDT 2009


On Jun 18, 2009, at 12:45 PM, Dave Weis wrote:

>
> I have a bunch of individual email messages from mail.app that have  
> been
> disassociated from their mailbox. I have tried copying them into the
> messages folder but they don't go because of two lines in the plist  
> at the
> end. I need to remove
>         <key>remote-id</key>
>         <string>4294</string>
> from 20,000 files. The number varies and the location at the end of  
> the
> file can move a few lines at a time. I've tried my regex magic on it  
> but
> don't have enough to get it working. Any help?

This works (at least on my .emlx files), and doesn't drop other string  
values you might need from the plist.

It does not do anything to protect plists in your message bodies  
though. I couldn't figure out how Apple was delimiting the plist at  
the end, or escaping plists in the body, and I was too lazy to read  
backwards from the end to find the last <plist> line.

Reads STDIN, writes STDOUT

--

#!/usr/bin/perl -w
use strict;

my $skip_next = 0;
while(<>) {
	if (/^\s*\<key\>remote\-id\<\/key\>\s*$/i) {
		$skip_next = 1;
	} elsif ($skip_next && /^\s*\<string\>\d+\<\/string\>\s*$/i) {
		$skip_next = 0;
	} else {
		print $_;
	}
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2746 bytes
Desc: not available
Url : http://cialug.org/pipermail/cialug/attachments/20090618/dfbef3b3/attachment.bin 


More information about the Cialug mailing list