in reply to match and edit block of text

Once you've decided what it is you need to comment out, then simply use;

s/^/#/

So, you could use something like;

while (<>) { if (/Alias/ .. /\/Directory/) { s/^/#/; } print OUTPUT; }

That is, if your intent is to comment out all lines starting from the one matching /Alias/ to the one matching /\/Directory/.

See the perlfunc man page, under s/// for how to use s///, the perlretut and/or perlrequick man page for how to write regular expressions, and the perlop man page for how the .. "flip-flop" operator works.

$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

Replies are listed 'Best First'.
Re^2: match and edit block of text
by js1 (Monk) on Jun 03, 2005 at 08:41 UTC

    Thanks for your reply. This did exactly what I wanted:

    # comment out icons section if (/Alias \/icons/ .. /\/Directory/) { ($newline=$_)=~s/^/#/; }