Find the answer to your Linux question:
Results 1 to 7 of 7
Is there a way to use the grep command in conjunction with an editor such as nano or vi so that I can remove the commented out lines from a ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    53

    grep command and then edit how ?

    Is there a way to use the grep command in conjunction with an editor such as nano or vi so that I can remove the commented out lines from a conf file and then proceed to edit it ?
    I can use grep -v "^#^" squid.conf (example ) which gives me a nicely tidy conf file but I can't edit it.
    Can this command be used with nano or ??
    -keevill-

  2. #2
    Just Joined!
    Join Date
    Feb 2011
    Location
    Oregon, USA
    Posts
    6
    Hmm, interesting idea. Never thought of that. Curious to see if anyone knows how to do this.

  3. #3
    Linux User ptkobe's Avatar
    Join Date
    Feb 2008
    Location
    Torres Vedras, PT
    Posts
    274
    interesting, indeed.

    If you really don't want the the comments you may replace the conf file with the grep output. Then edit it. (your command as an extra ^)

    # cp squid.conf squid.conf.bak
    # grep -v "^#" squid.conf > squid.conf
    # nano squid.conf

    I think you cant expect to edit without (without seeing?) the comments and save it back with the comments, right? Then again, what do I know?

    Regards
    Luis

  4. #4
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,102
    Code:
    sed -i /^#/d squid.conf
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Oct 2009
    Posts
    53
    Quote Originally Posted by Irithori View Post
    Code:
    sed -i /^#/d squid.conf
    I'm not sure that I follow this command ..when in root I type @ terminal
    sudo sed -i /^#/d squid.conf
    I get absolutely nothing ..should an editor open up ??
    -keevill-

  6. #6
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,102
    sed is a stream editor.
    The idea is, that it is *not* interactive, ie: no gui will be shown. In fact: sed has none.
    It reacts to commands and regular expressions.

    sed -i /^#/d squid.conf

    sed is called to work on a file squid.conf.
    /^#/ match lines, that begin with a #
    and delete them /d
    -i work in-place. That means: modify squid.conf instead of just printing the output to stdout.
    You must always face the curtain with a bow.

  7. #7
    Just Joined!
    Join Date
    Oct 2009
    Posts
    53
    Quote Originally Posted by Irithori View Post
    sed is a stream editor.
    The idea is, that it is *not* interactive, ie: no gui will be shown. In fact: sed has none.
    It reacts to commands and regular expressions.

    sed -i /^#/d squid.conf

    sed is called to work on a file squid.conf.
    /^#/ match lines, that begin with a #
    and delete them /d
    -i work in-place. That means: modify squid.conf instead of just printing the output to stdout.
    Excellent command and explanation !!
    Many thx,
    -keevill-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...