Grep and matching end of line (anchoring)

Dave Korn dk@artimi.com
Fri Nov 19 18:31:00 GMT 2004


> -----Original Message-----
> From: cygwin-owner On Behalf Of Buchbinder, Barry (NIH/NIAID)
> Sent: 19 November 2004 15:17

> This should work whether or not one is on a text mount or for 
> the file has DOS or Unix line endings:
>
> 	cat files.txt | grep -E '\.h^M?$'

  Always test before posting.  Even a one liner.  That doesn't work, or at
least NFM:

dk@mace /test/grep-test> od -c test.dos.txt
0000000   H   e   l   l   o       w   o   r   l   d  \r  \n
0000015
dk@mace /test/grep-test> od -c test.unix.txt
0000000   H   e   l   l   o       w   o   r   l   d  \n
0000014
dk@mace /test/grep-test> grep -E 'ld^M?$' *
dk@mace /test/grep-test> grep -E 'd^M?$' *
dk@mace /test/grep-test> grep -E '.^M?$' *
dk@mace /test/grep-test>

  Grep knows there's a char there, but it won't match it with ^M.

dk@mace /test/grep-test> grep -E '.$' *
test.dos.txt:Hello world
test.unix.txt:Hello world
dk@mace /test/grep-test> grep -E 'd.$' *
test.dos.txt:Hello world
dk@mace /test/grep-test> grep -E 'd^M$' *
dk@mace /test/grep-test> grep -E 'd^m$' *
dk@mace /test/grep-test>


  What makes you think grep understands ^ notation to indicate control
chars?  It doesn't say so in the info page.  (It doesn't recognize [\r]
either.)

  Actually, it seems that grep

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list