For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2004 > Perl oneliner to delete lines from a file









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 Perl oneliner to delete lines from a file
Ramprasad A Padmanabhan

2004-08-09, 3:55 am

I want to write a command line perl 'script' to delete one or more
lines from a file , by line number


for eg in sed I can do the same in two steps

cat FILENAME | sed -e '1,10d' >FILENAME.TMP
mv FILENAME.TMP FILENAME

The above mechanism has a lot of pitfalls , like maintaining
permissions , making sure FILENAME.TMP does not already exist etc.
That is why I want to do it with "perl -i "
but I dont want to write a full script for this , because I am going to
run it on remote machines ( automated ) , and I cant ftp the script
everywhere

Any suggestions
Thanks
Ram


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com