Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    6

    Unanswered: removing specific lines in a file

    Another stupid question...
    I have a file, I need to remove all the lines in the file that start with a specific character (in this case, #). Is there any easy unix command to do this or should I write a mini program to do it for me?

    Thanks!

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    The only stupid question is the one not asked [(c) don't remember]

    Code:
    ex - myFile.txt <<EOF
    %s/^#.*/replacedPattern/g
    wq!
    EOF
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  3. #3
    Join Date
    Aug 2004
    Posts
    6
    Thanks! That definitely helped

  4. #4
    Join Date
    Jun 2004
    Posts
    29

    try egrep

    Another tool you might try is egrep. To remove lines which start with a #
    Code:
    egrep -v ^# infile > outfile
    The ^ symbol anchors the # to the start of the line so you don't remove a line such as

    data # more data

    The -v flag means lines other than those which match the pattern.

    man egrep for more info

Posting Permissions

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