Find the answer to your Linux question:
Results 1 to 4 of 4
I am trying to use grep or sed to locate all nonblank lines that do not begin with a // /* or # in a file. egrep ".+" will find ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10

    using grep or sed to find non blank lines not starting with ...

    I am trying to use grep or sed to locate all nonblank lines that do not begin with a // /* or # in a file.

    egrep ".+" will find all nonblank lines but I'm not sure about the rest

  2. #2
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    This should work:

    Code:
    egrep -v '(^//|^/\*|^#|^$|^[[:space:]]+$)'

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Posts
    10
    it works thanks

    correct me if I'm wrong but the :space: isn't nescecary. Also why did you put it inside two sets of [] ? The ^$ already checks to see if a line is empty.

  4. #4
    Linux Newbie
    Join Date
    Mar 2009
    Posts
    228
    With [[:space:]] the outer brackets indicate a 'bracket expression', the [:space:] is the syntax to look for spaces and TABs.

    The ^$ checks for an empty line. If the a line has only spaces or TABs (ie: [:space:]) in it it wouldn't match.

Posting Permissions

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