On Wed, 10 Sep 2003, Herculano de Lima Einloft Neto wrote:

>   
>   I guess this is an easy one.. how can I insert / delete something at
> the beggining of each line of a block in vi? Still can't figure it,
> though there must be at least ten ways.
> 

On way is to use PERL! Since I'm familiar with PERL, I'm gonna give u a
PERL solution:

use this small PERL program and call it comment.pl

--------------------------------------------
#!/usr/bin/perl
open(FILE,"<./myfile.txt") || die "can't open myfile.txt";

$lines=0;

while(<FILE>){
$lines=$lines+1;
if($lines>=3&&$lines<=4){s/$_/\#$_/;} # this specifies which lines to comment
push(@temp, $_);
 }
close(FILE);

open(FILE2,">./comment.txt") || die "can't open comment.txt"; #the commented file :-)

print FILE2 "@temp";
close(FILE2);
----------------------------------------------------------

ur initial file: myfile.txt
ur commented file: comment.txt

$lines governs which lines you want to comment out. This example shows the
commented line "#something" to be 3rd and 4th line.

Btw here it's commented by a "#".. u can specify other things! Just modify
the above and run it!



regards,

Didier

---
PhD student

Singapore Synchrotron Light Source (SSLS)
5 Research Link,
Singapore 117603

Email: [EMAIL PROTECTED] or [EMAIL PROTECTED]
Website: http://ssls.nus.edu.sg
www.microtronyx.com (Microtronyx Computer Consulting Group Singapore)


-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://www.redhat.com/mailman/listinfo/redhat-list

Reply via email to