LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2006, 06:00 AM   #1
mahabooba
Member
 
Registered: Dec 2005
Posts: 43

Rep: Reputation: 15
Shell scripting :: comment N line in vi editor


Hi,
Using shell scripting how we can comment N line.
Please help me in this regard.


Thank and Regards,
Mahaboob
 
Old 07-27-2006, 07:33 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I'm not sure which you're doing here.
In the vi editor, the command would be like
Code:
:3s/^/# /
Using sed would be something like
Code:
sed -i '3s/.*/# &/' file.txt
 
Old 07-28-2006, 12:58 AM   #3
mahabooba
Member
 
Registered: Dec 2005
Posts: 43

Original Poster
Rep: Reputation: 15
Thank you homey,
But How do I delete comments in Nth line.
Please do let me know.

-
Mahaboob
 
Old 07-28-2006, 02:50 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,349

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
:3s/^#.*//
for line 3
 
Old 07-28-2006, 05:58 AM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
If you just want to delete the comments which have a space after them and not the words in that line,
For example:

this is line one
this is line two
# this is line three

in vi ...
Code:
:3s/^# //
Using sed...
Code:
sed -i '3s/^# //' file.txt
this is line one
this is line two
this is line three
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
command line options for firefox for shell scripting. dr_zayus69 Programming 1 05-25-2005 11:36 AM
Shell Scripting: How to pick lines out of files by line number. Louie55 Programming 3 03-22-2005 06:18 PM
Looking for GUI Shell Scripting Editor L1nu*M0m Linux - Software 3 06-08-2004 07:54 PM
line addressing with grep (shell scripting) j2dizzo Linux - General 13 03-03-2004 09:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:08 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration