#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2005
    Posts
    33
    Rep Power
    13

    Incorrect grep behaviour?


    Hello,

    I am trying to perform the simple task of counting the number of lines in a file that have the line ending '\n'.

    I created a file that definitely has 10 newlines.

    grep -P '\n' 10lines.txt

    Prints out the 10 lines.

    grep -Pc '\n' 10lines.txt

    Prints the number '5'.

    Please can someone tell me what the heck is going on.

    I am running grep (GNU grep) 2.5.1 on OS X Lion.
    Last edited by gas_panic!; October 14th, 2014 at 10:21 AM.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,478
    Rep Power
    1875
    The perl re for end of line is $

    Eg.
    Code:
    $ grep -P -c '$' strace1.log
    97
    $ wc strace1.log
      97  700 6979 strace1.log
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo