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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-18-2007, 01:49 AM
|
#1
|
Member
Registered: Feb 2006
Posts: 97
Rep:
|
listing non-comment lines
In vi editor how can I list out the lines without stating from #
|
|
|
09-18-2007, 06:34 AM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
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.
|
|
|
09-18-2007, 07:07 AM
|
#3
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
If you just want to highlight lines that don't start with '#' in vi, use:
If you want to use sed, you could do this:
Code:
sed -en '/^[^\#]/p' /path/to/file
|
|
|
09-18-2007, 08:13 AM
|
#4
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep: 
|
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
|
|
|
09-18-2007, 01:50 PM
|
#5
|
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141
Rep: 
|
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).
|
|
|
09-18-2007, 08:55 PM
|
#6
|
Senior Member
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep: 
|
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.
|
|
|
All times are GMT -5. The time now is 10:23 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|