Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a very long config file with hardly comment and uncomment line Now I want to print out lines with uncomment

# LOCAL PATHNAME INFORMATION
#
# The queue_directory specifies the location of the Postfix queue.
# This is also the root directory of Postfix daemons that run chrooted.
# See the files in examples/chroot-setup for setting up Postfix chroot
# environments on different UNIX systems.
#
queue_directory = /var/spool/postfix

# The command_directory parameter specifies the location of all
# postXXX commands.
#
command_directory = /usr/sbin

I want the output is lines with no comment

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

share|improve this question
    
can you give an example of such a line? –  Christian Feb 5 '10 at 7:01
    
Please clarify, I'm having trouble parsing your sentences. –  Teddy Feb 5 '10 at 7:29
    
example the main.cf config file of Postfix MTA # LOCAL PATHNAME INFORMATION # # The queue_directory specifies the location of the Postfix queue. # This is also the root directory of Postfix daemons that run chrooted. # See the files in examples/chroot-setup for setting up Postfix chroot # environments on different UNIX systems. # queue_directory = /var/spool/postfix # The command_directory parameter specifies the location of all # postXXX commands. # command_directory = /usr/sbin # => I want the line with no comment –  billyduc Feb 5 '10 at 8:25
    
@billyduc, as your comments below show, a script wasn't needed, a command is enough. And it's a good idea to give an idea of the intended Operating System and scripting language (if that's what you want). –  pavium Feb 5 '10 at 8:42

2 Answers 2

up vote 2 down vote accepted
egrep -a -v '^[[:space:]]*#' config_file | egrep -a '[[:print:]]' | less

will account for spaces before the #. Pipe it to less and you can view it easily

replace config_file with $1 and put the line in /usr/local/bin/cless and chmod it +x and you have nice little script whenever you need it.

cless config_file
share|improve this answer
    
Your script work great ! –  billyduc Feb 5 '10 at 8:32

Assuming that commented lines begin with "#" in the first position:

grep -v '^#' config_file

will print all the lines that do not begin with "#" in the file "config_file".

share|improve this answer
    
your script also work and easy to remember ... thank you –  billyduc Feb 5 '10 at 8:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.