LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-18-2007, 01:49 AM   #1
scbops
Member
 
Registered: Feb 2006
Posts: 97

Rep: Reputation: 15
listing non-comment lines


In vi editor how can I list out the lines without stating from #
 
Old 09-18-2007, 06:34 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
In vi command mode, you can filter vi output through some external application (the filter).

The command syntax would begin like this:
:!gawk or :!sed, followed by the gawk or sed script to filter out lines beginning with #.

I'm don't use gawk or sed enough to be able to tell you the entire command to use. I hope this points you in the direction of a solution.
 
Old 09-18-2007, 07:07 AM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
If you just want to highlight lines that don't start with '#' in vi, use:
Code:
/^[^#].*$
If you want to use sed, you could do this:
Code:
sed -en '/^[^\#]/p' /path/to/file
 
Old 09-18-2007, 08:13 AM   #4
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
Simplest:

Gilead's vi will work, but you don't need the .*$

Just /^[^#] and then n (next) to go on through successive lines (or shift n to go backwords). This is what I do all the time when editing .conf files, because they often have so many comments.

If you are just looking for non comment lines and don't need to do any editing (just a real quick, "are there any" or "what are they"), use grep and maybe more if there are lots of them.

$ grep '^[^#]' blah.conf | more
 
Old 09-18-2007, 01:50 PM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
To just find the lines that don't start with '#' choogendyk is correct, just /^[^#] will do. As I said though, if you want to highlight the lines, adding the match for the rest of the line and using /^[^#].*$ gives an easier to see display (depending on your vi's colour settings).
 
Old 09-18-2007, 08:55 PM   #6
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
I guess I'm just kind of old fashioned when it comes to Unix/Linux. Color display vi and GUI kind of stuff just aren't in it for me. I don't get highlights. I just want my cursor to land at the right location. My fingers naturally follow the vi navigation keys. They do it even on the command line in ksh. In many of the original video games (the old asteroids for example), the navigation keys were the same as vi.
 
  


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
Asterisk box to connect VoIP lines with normal telephone lines. sraju Linux - Software 1 11-08-2006 12:38 AM
comment the lines in virtuertable will receive old emails in SquirrelMail ? kkeith Linux - Newbie 0 07-10-2006 05:37 AM
awk/gawk/sed - read lines from file1, comment out or delete matching lines in file2 rascal84 Linux - General 1 05-24-2006 09:19 AM
Is there a way to filter out all the comment lines in a configuration file... Akhran Linux - Newbie 3 12-07-2005 11:07 AM
printer printing vertical lines at beginning and end of lines makhand Linux - Hardware 0 09-02-2005 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:23 PM.

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