List Info

Thread: Re: How to remove unwanted lines from file.




Re: How to remove unwanted lines from file.
country flaguser name
Czech Republic
2007-05-10 06:03:37

From: "Ramesh Polepalli&quot; < ramesh.polepalli%40mformation.com">ramesh.polepallimformation.com>
> I want to remove some lines containing some specific characters in a
> file.
&gt;
> Is there any command line "One liner"; available to do the same in Perl
>; without having to create new file and renaming it back?

perl -pi.bak -e "$_ = '' if /ignorestring/" sourcefile
===== Jenda%40Krynicky.cz">JendaKrynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

__._,_.___
.

__,_._,___
Re: How to remove unwanted lines from file.
country flaguser name
United States
2007-05-10 06:12:27

>>&gt;>> "Jenda" == Jenda Krynicky < Jenda%40Krynicky.cz">JendaKrynicky.cz> writes:

Jenda>; perl -pi.bak -e "$_ = '' if /ignorestring/" sourcefile

I find

perl -ni.bak -e 'print unless /ignorestring/" sourcefile

saner to read. Somehow, the idea of "print ''" seems wasteful,
and potentially dangerous if "-l&quot; is involved.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )