# Command to comment multiple lines in K shell prgm



## lbanil (Mar 9, 2008)

Hello,

I have a big K shell program used to call other perl scripts using an AIX / Linux m/c & generate few output txt files.

I know that I can comment a single line using # at the start of a line.
I would like to know if there is a command to comment multiple lines in a .k file something similar to "=begin_comment" or "=for comment" "=cut" commonly used in PERL

Adding & removing a # at the beginning of each line in a big file..repeatedly..is a big waste of time!!

Thanks,
Anil


----------



## shuuhen (Sep 4, 2004)

I've never seen shells that support multiline comments (although I typically try to use something like Ruby instead of a shell when possible). There is an interesting workaround for bash that you could try for the Korn shell: http://www.mail-archive.com/[email protected]/msg01663.html

Another option (what I typically use) is use a special search and replace that replaces the start of the line.

In vim (maybe vi too?):

# To comment lines 53-73
:53,73s/^/#/

# To uncomment lines 53-73
:53,73s/^#//

# General syntax
:_start_line_,_end_line_*s*/_find_/_replace_/_options_

The colen gets you to the line where you enter the command. _start_line_ and _end_line_ are the start and end lines to comment. Note that the letter 's' is just there to tell vim to search. _find_ is what you want to match, in the specific example I used a regular expression to match the start of a line. _options_ can be blank or can have something like *gc* for global and confirm.

My little trick should probably work for any editor that supports regular expressions. Although do note that from what I've seen, text editors can require you to escape some characters you normally would not in say a Perl or Ruby regular expression.


----------

