On Aug 18, 2011, at 10:01 PM, Macs R We wrote:
> sed can do this.
>
> (Can I do this with sed? No, but lots of other people can and have. :-)
Don't bother.
Write a simple state machine in PERL.
Just … do it.
All the other paths lead to madness.
#!/usr/bin/perl
$1 = 0;
while (<>)
{
if ($x == 1 && /\/dev\/disk.*FDisk_partition_scheme/) { $x++; }
if ($x == 1 && /\/dev\/disk.*\/Volumes\/XcomQemu/} { $x++; }
…
}
I think you get the idea.
There are probably more efficient ways to do it, but … this way, the problem
just up and disappears.
> On Aug 18, 2011, at 8:22 PM, Michael Gersten wrote:
>
>> I'm trying to match a multiline pattern in a program's output.
>>
>> I've got a shell script that runs from cron. It has some output. Normally
>> it's pointless, and clutters my mailbox.
>>
>> I've determined that if the program runs properly, the output will match the
>> following:
>>
>> /dev/disk.*FDisk_partition_scheme
>> /dev/disk.*/Volumes/XcomQemu
>> sending incremental file list
>>
>> sent.*
>> total size is.*
>> "disk." unmounted.
>> "disk." ejected.
>>
>> Note the following:
>> 1. It's multiple lines.
>> 2. It has "." and ".*" (only).
>>
>> I've looked at expect, and grep(1), re_format(7), and regex(3). Expect
>> doesn't seem to like multiple lines of matching. Nothing in the grep family
>> indicates anything about searching for a newline in the middle of a pattern
>> -- at best, the "patterns in a file" give one pattern per line.
>>
>> So what's the best way to test the output of one command against an expected
>> behavior? If something goes wrong, I want to see it; if nothing goes wrong,
>> I don't want to see anything.
>>
>> (If you're curious, it's mounting a virtual hard drive, rsync'ing the data
>> of interest into an HFS+ directory, and then unmounting it. I don't want
>> time machine copying a large virtual hard drive when the files of interest
>> are tiny.)
>>
>>
>> Michael
Aloha,
Michael.
--
"Please have your Internet License
and Usenet Registration handy..."
_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk