Operating System - HP-UX
1753481 Members
4106 Online
108794 Solutions
New Discussion юеВ

how to view the commented line in vi file

 
SOLVED
Go to solution
rajesh73
Super Advisor

how to view the commented line in vi file

pls find the below vi file.

example:
vi sudoers
1.# Cmnd alias specification
2.STORE /usr/sbin/frestore, /usr/sbin/backup
3.UMOUNT = /usr/sbin/umount
4.MOUNT = /usr/sbin/mount
5.# Host alias specification


the above example i want to view the line number 2,3,4 .because i want to see the uncommented line in the vi file

pls help me
17 REPLIES 17
Steven Schweda
Honored Contributor

Re: how to view the commented line in vi file

> how to view the commented line in vi file

What is "vi file"? A plain-old text file
which was created by "vi"?

> [...] i want to view [...]

Can't you see them now?

Do you mean something like this?:

alp$ grep -v '^#' 1483561.txt
STORE /usr/sbin/frestore, /usr/sbin/backup
UMOUNT = /usr/sbin/umount
MOUNT = /usr/sbin/mount

man grep
rajesh73
Super Advisor

Re: how to view the commented line in vi file

hi thanks for your replay .

my request is

in this sudoers file ,i want to view only uncommneted line, how to view
g3jza
Esteemed Contributor
Solution

Re: how to view the commented line in vi file

#grep -v '#' /etc/sudoers
rajesh73
Super Advisor

Re: how to view the commented line in vi file

thanks for replay.

Steven Schweda
Honored Contributor

Re: how to view the commented line in vi file

> #grep -v '#' [...]

Ok, if you want to reject any line with a "#"
in it anywhere. '^#' is a little more
selective.

> [...] only uncommneted line [...]

Define "uncommneted line". Is
/util/search.sh '###' > /tmp/fred.out
an "uncommneted line"?

Everything's complicated, and a vague problem
statement can lead to a sloppy "solution".


> Jun 10, 2011 04:42:59 GMT 8 pts

What? Did I use the wrong file name?
g3jza
Esteemed Contributor

Re: how to view the commented line in vi file

Steven:
I haven't seen any standard unix configuration files, which would NOT have the '#' at the beginning of the line :) , that's why I'm always using -v '#' .

Steven Schweda
Honored Contributor

Re: how to view the commented line in vi file

> I haven't seen any standard unix
> configuration files, which would NOT have
> the '#' at the beginning of the line :) ,
> that's why I'm always using -v '#' .

The original question said "vi file"
(whatever that means), not "standard unix
configuration files". However, let's look at
the example of "sudoers". I'm not a big sudo
user, so I know nothing, but a quick Google
search found some documentation which
suggests that "sudoers" might contain
notation like, say,
#include /etc/sudoers.local
which would make this task a little more
chancy. Also, it appears that one is allowed
to use "#" to add a comment to the end of a
normal line, and it seems to be a part of the
"sudoers" syntax, as in "#uid" or "%#gid".

So, discarding any line which contains "#"
anywhere would seem in this example to risk
losing considerable useful information.

If you would like to expand "^#" to include
white space before "#" (and/or "#include" at
the beginning of a line), then I wouldn't
complain.

> Everything's complicated, [...]

A simple solution to a problem is normally
better than a more complicated one, unless
that simpler "solution" doesn't actually
solve the problem. (Of course, having a
clear and complete definition of the problem
is helpful, but this is often difficult to
obtain.)
щ╗ЮчЗГ
Valued Contributor

Re: how to view the commented line in vi file

saludos,

Do a grep -v for all lines starts with # which can be identified using "^#" in the output of the cat command.

cat /etc/sudoers |grep -v "^#"

All lines starts with a # will be eliminated in the output.

todo lo mejor
Man's mind, once stretched by a new idea, never regains its original dimensions
Steven Schweda
Honored Contributor

Re: how to view the commented line in vi file

> cat /etc/sudoers |grep -v "^#"

Why didn't _I_ think of that? No, wait...

Note that the "cat" is not needed.