On Mon, 2004-08-09 at 07:34, Ramprasad A Padmanabhan wrote:
> I want to write a command line perl 'script'  to delete one or more 
> lines from a file , by line number

Hi :-)

If I understand correctly, you want to delete lines X to Y from a file,
right?

perl -i -ne 'print unless 1..10' file

that should do the trick :-)


The explanation follows:

-i => in-place edit (you apparently already know what this does
-n => for all lines, apply script
-e => evaluate the following script

print unless 1..10

Well... the '..' operator has been explained every other mail on this
list :-| Basically, this one returns true if you're between lines 1 and
10 (inclusive), which means those lines won't get printed, but all
others will.

HTH,

jac

PS: If you'd like a more detailed explanation of the .. operator or
something else, just say it :-) I'm just not explaining it because
you've probably already read about it here... :-)

> 
> 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 
-- 
José Alves de Castro <[EMAIL PROTECTED]>
  http://natura.di.uminho.pt/~jac

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to