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?
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?
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
Yeah, I got the solution
In Notepad++, select the lines you want to comment out. Press ctrl+K , it will put # before the line.
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.
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 #.