LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 04-10-2013, 01:19 AM   #1
rockstar05
Member
 
Registered: Dec 2011
Posts: 41

Rep: Reputation: Disabled
Angry 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
 
Old 04-10-2013, 01:38 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 530

Rep: Reputation: 109Reputation: 109
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.
 
Old 04-10-2013, 01:40 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.

Last edited by druuna; 04-10-2013 at 02:06 AM. Reason: spelling: noy -> not
 
Old 04-10-2013, 01:59 AM   #4
rockstar05
Member
 
Registered: Dec 2011
Posts: 41

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 06:12 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration