Find the answer to your Linux question:
Results 1 to 4 of 4
Hi all, I would like to know if there is any way to remove commented lines ('#' ) from a file without opening it. I heard that this can be ...
  1. #1
    Just Joined! AceAll's Avatar
    Join Date
    May 2005
    Posts
    67

    removing lines with #

    Hi all,

    I would like to know if there is any way to remove commented lines ('#' ) from a file without opening it. I heard that this can be acheived using sed. I am not aware of it. Please let me know.

    Any help would be appreciated.

    Thanks.

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    I cant do SED (yet) but you might want to read:
    http://www.student.northpark.edu/pem...d/sed1line.txt

    This always helps me If I need something done Quickly.
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Location
    Salt Lake City, UT, USA
    Posts
    32
    Code:
    sed -e '/^#/d' original.txt > new.txt
    will match any lines with # at beginning of line, but not if it is tabbed or spaced into the line.
    Code:
     sed -e '/^ *#/d' original.txt > new2.txt
    will match lines where # preceeded by any number of spaces at the beginning of the line.

    I haven't yet dabbled in saving the file on the fly instead of writing a 2nd new file. Good luck!

  4. #4
    Just Joined! AceAll's Avatar
    Join Date
    May 2005
    Posts
    67
    Thanks guys. That was helpful.

    Best,
    AceAll

Posting Permissions

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