delete multiple lines with sed
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > delete multiple lines with sed




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    delete multiple lines with sed  
onlineviewer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

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,






[ Post a follow-up to this message ]



    Re: delete multiple lines with sed  
Jim Cochrane


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

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 ***





[ Post a follow-up to this message ]



    Re: delete multiple lines with sed  
onlineviewer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

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 ?






[ Post a follow-up to this message ]



    Re: delete multiple lines with sed  
onlineviewer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

I'm new at this, but im pretty sure there's an easier way...






[ Post a follow-up to this message ]



    Re: delete multiple lines with sed  
Jim Cochrane


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:53 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register