|
Home > Archive > Unix Programming > April 2006 > delete multiple lines with sed
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
delete multiple lines with sed
|
|
| onlineviewer 2006-04-27, 7:56 am |
| Hello
I would like to be able to delete multiple lines with sed in one
command.
This is what i have right now:
system '/usr/bin/sed /string1/d /tmp/file.in > /tmp/file.out';
I would like to have many lines deleted with different strings in one
command, something like:
system '/usr/bin/sed /string1,string2,string3,string4/d /tmp/file.in >
/tmp/file.out';
Syntax is wrong, but you get the picture..
Thank you,
| |
| Jim Cochrane 2006-04-27, 7:56 am |
| On 2006-04-20, onlineviewer <lancerset@gmail.com> wrote:
> Hello
>
> I would like to be able to delete multiple lines with sed in one
> command.
> This is what i have right now:
>
> system '/usr/bin/sed /string1/d /tmp/file.in > /tmp/file.out';
>
> I would like to have many lines deleted with different strings in one
> command, something like:
>
> system '/usr/bin/sed /string1,string2,string3,string4/d /tmp/file.in >
> /tmp/file.out';
>
> Syntax is wrong, but you get the picture..
> Thank you,
>
sed '/expr1/d;/expr2/d;/exprn/d'
--
*** Posted via a free Usenet account from http://www.teranews.com ***
| |
| onlineviewer 2006-04-27, 7:56 am |
| 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 ?
| |
| onlineviewer 2006-04-27, 7:56 am |
| I'm new at this, but im pretty sure there's an easier way...
| |
| Jim Cochrane 2006-04-27, 7:56 am |
| 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 ***
|
|
|
|
|