List Info

Thread: How to remove unwanted lines from file.




How to remove unwanted lines from file.
country flaguser name
United States
2007-05-10 02:04:52

Hi,

I want to remove some lines containing some specific characters in a
file.

I can easily do it using grep redirecting the output to some other file
and renaming the new file with source file name

In Shell

---------------

cat Sourcefile | grep -v "ignorestring" > newfile

mv newfile Sourcefile

Is there any command line "One liner"; available to do the same in Perl
without having to create new file and renaming it back?

Thanks in advance for any help.

Ramesh Polepalli

mFormation Technologies Inc.
Direct Line: +91 80 6620 5939
Switchboard: +91 80 6620 5900

http://www.mformation.com


Visit WWW.MFORMATION.COM and see how the MFORMATION SERVICE MANAGER can help you to transform your business.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: How to remove unwanted lines from file.
country flaguser name
United States
2007-05-10 04:46:17

>>&gt;>> "Ramesh" == Ramesh Polepalli < ramesh.polepalli%40mformation.com">ramesh.polepallimformation.com> writes:

Ramesh&gt; cat Sourcefile | grep -v "ignorestring&quot; > newfile

That's a "useless use of cat" - grep for that for details.

Ramesh&gt; mv newfile Sourcefile

Ramesh> Is there any command line "One liner"; available to do the same in Perl
Ramesh> without having to create new file and renaming it back?

Yes, it's called "in-place editing&quot;, and is described on "perldoc perlrun&quot;
under the "-i&quot; switch. If you have any questions after reading that
document, please ask again.

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