LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Need a help (http://www.linuxquestions.org/questions/linux-server-73/need-a-help-4175457588/)

rockstar05 04-10-2013 01:19 AM

Need a help
 
Hi All,

I want to comment some lines in my cfg file.
So, I don't want to comment single single line.

Is there any solution that make me easy and comment all the lines in cfg file as in a single command in Vi editor.

Thanks in advance

eklavya 04-10-2013 01:38 AM

If you want to make comment for multiple lines in shell, this is the way
Code:

#!/bin/bash
echo "Say Something"
<<COMMENT1
    your comment 1
    comment 2
    blah
COMMENT1
echo "Do something else"

Now it will treat 3 lines "your comment 1", "comment 2" & "blah" as a comment.
Now if you want to make comment some more lines in same file, use attribute COMMENT2, Do not use same attribute in same file multiple times.

druuna 04-10-2013 01:40 AM

Not sure what it is you want, maybe eklavya has assumed correctly, if not:

To comment out lines 4, 5 and 6:
Using vi:
Code:

in command mode
:4,6s/^/#/

Or, using sed:
Code:

sed -i.bak '4,6s/^/#/' infile
Commenting out all lines:
Code:

in command mode
:%s/^/#/

Or, using sed:
Code:

sed -i.bak 's/^/#/' infile
If neither of us have understood: Please elaborate.

rockstar05 04-10-2013 01:59 AM

Quote:

Noy sure what it is you want, maybe eklavya has assumed correctly, if not:

To comment out lines 4, 5 and 6:
Using vi:
Code:
in command mode
:4,6s/^/#/
Or, using sed:
Code:
sed -i.bak '4,6s/^/#/' infile
This would be more clear to me.

Thanks to druuna also appriciate to eklavya.

Solved


All times are GMT -5. The time now is 04:58 PM.