04-27-06 12:56 PM
On 2006-04-20, onlineviewer <lancerset@gmail.com> wrote:
> Hi
>
> This works great. I'm trying to get this working within a PERL script,
> something like this:
>
> system /usr/bin/sed '/string1/d;/string2/d;/string3/d' /tmp/file.in >
> /tmp/filein;
>
> Not working though. I guess i can use something like an if statement
> and the matching operator. Any ideas ?
>
You have plenty of filtering tools in PERL and it's more efficient to just
use them - e.g.:
#!/usr/bin/perl
use strict;
use warnings;
open my $infile, "</tmp/msg" || die "Failed to open input file";
open my $outfile, ">/tmp/msg.filt" || die "Failed to open output file";
my @filtered = grep {
$_ !~ /expr1|expr2|expr3/
} <$infile>;
for my $l (@filtered) {
print $outfile $l;
}
but if you have to use sed within PERL (perhaps your teach said to do
this), it's probably easiest to just supply one string argument to system -
e.g.:
system "sed '<sedcmds>'";
replacing <sedcmds> with the needed sed commands, of course.
--
*** Posted via a free Usenet account from http://www.teranews.com ***
[ Post a follow-up to this message ]
|