Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Displaying config files without comments
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Displaying config files without comments

I want to display config files without comments ( # or ; ) & blank lines

I use

cat file | grep -v ^#

but it won't work for files that use ; as comment or remove blanks lines

Any great alias you guys may suggest?

Comments

  • I found one guys
    cat file | egrep -v "^\s*(#|;|$)"
    Hope it helps someone

  • khavkhav Member
    edited September 2014

    @Zen
    Can someone tell me how to create an alias for the command above

  • No need to use cat.

    egrep -v "^\s*(#|;|$)" <file>

    If you use bash, add this to .bashrc:

    ncom () { egrep -v "^\s*(#|;|$)" $1; }

    to create alias "ncom" for the command above.

  • @khav said:

    echo 'newcommand() { cat "$@" | egrep -v "^\s*(#|;|$)" ;}' >> ~/.bashrc

    And run the command like this

    newcommand file

  • khavkhav Member
    edited September 2014

    @aus

    I added it to bashrc but i still get newcommand not found

  • @khav said:
    t3k9 i added the following to .bashrc
    cleanconfig () { egrep -v "^\s*(#|;|$)" $1; }

    Do i need to reboot the server or logout for it to take effect ?

    Type bash and it should take effect.

    Thanked by 1khav
  • you can use multiple -e statements. makes it easier to read.
    also filters empty lines...

    grep -v -e ^# -e '^;' -e '^[ \t]*$' /etc/apt/sources.list
    
  • aus said: Type bash and it should take effect.

    With yesterday's discovery this phrase gets a completely new meaning :-D

  • @aus thanks it worked

    @alessio a patch for bash has already been issued :)

Sign In or Register to comment.