-1

Can anyone suggest how to comment particular lines in the shell script?

Suppose I have a script of 500 lines and I want to comment 150 lines (from "300 to 450"), How to comment it at a time?

melpomene
  • 84,125
  • 8
  • 85
  • 148
Aditya Dhanraj
  • 189
  • 1
  • 1
  • 12

4 Answers4

1

If you use vi as your text editor you could use

:300,450s/^/#&/

This will prepend # to all lines from 300 to 450.

Or you could go to the first line you want to comment, mark it with label a using

:ma

then go to the last line and enter

:a,.s/^/#&/

This will do the same substitution from the line marked with a to the current line

Bodo
  • 9,287
  • 1
  • 13
  • 29
1

Yeah, I got the solution

In Notepad++, select the lines you want to comment out. Press ctrl+K , it will put # before the line.

Aditya Dhanraj
  • 189
  • 1
  • 1
  • 12
0

Many text editors provide feature of recording macros. I specifically find this fearure easy in Notepad++.

Here is a good tutorial if you want to understand more about it:

https://www.youtube.com/watch?v=--wY1sWFVwI

So for you to avoid reworking:

Rocord a macro that

1.) goes to begin of the line

2.) adds a #

3.) changes the cursor to new line

and then you can run it for 150 times in one click,when you are at line number 300.

0

perl -ne 'if(($.>300)&&($.<450)){print "#$_"} else {print}' yourfilename

This iterates over the lines and if the line number is in the range you specify, prepends a #.

user1717259
  • 2,717
  • 6
  • 30
  • 44