Cygwin grep and EOL

A CVS log file contains all the versions, from cvs log xxx. For a task at work I need to extract the dates of all the revision 1.1s

RCS file: /cvs/asp/.../TestJob.java,v
Working file: G:/.../TestJob.java
head: 1.40
branch:
locks: strict
access list:
symbolic names:
XXX: 1.13
YYY: 1.40
keyword substitution: kv
total revisions: 56; selected revisions: 56
description:
----------------------------
revision 1.40
date: 2009/01/26 22:29:06; author: cn; state: Exp; lines: +2 -1 xxxxxxx
----------------------------
...
----------------------------
revision 1.1
date: 2004/02/02 12:22:36; author: dc; state: Exp; lines: +242 -0 xxxxxxx
----------------------------

so I want to look for all the lines that contain ONLY “revision 1.1”, and print them, plus the line after for context.

bash-3.2$ grep -A 1 '^revision 1\.1$' log.txt

Try it:
bash-3.2$ grep -A 1 '^revision 1\.1$' log.txt
bash-3.2$

Nothing. Huh?

More playing. Use Bash, not DOS shell.
Use Perl
perl -e "while (<>) { if /^revision 1\.1$/ {print $_; } }" < log.txt
Which works, but to give it the context requires some temp vars etc.

So why doesn’t grep work?

Could the EOL chars be the problem? The Cygwin utils install and ask about EOL chars, and I left as Unix.

My file:
00000000h: 0D 0A 52 43 53 20 66 69 6C 65 3A 20 2F 63 76 73 ; ..RCS file: /cvs ...
00000060h: 54 65 73 74 4A 6F 62 2E 6A 61 76 61 2C 76 0D 0A ; TestJob.java,v..

Using SciTE, Change line end chars to LF only (Mac format?). Still no work.

SO I created a file on the Mac (BSD) with vi:
00000000h: 72 65 76 69 73 69 6F 6E 20 31 2E 31 0A 72 65 76 ; revision 1.1.rev
00000010h: 69 73 69 6F 6E 20 31 2E 32 2E 32 0A 72 65 76 69 ; ision 1.2.2.revi
00000020h: 73 69 6F 6E 20 31 2E 30 0A 31 2E 30 0A 32 2E 30 ; sion 1.0.1.0.2.0
00000030h: 0A 31 2E 32 2E 32 0A ; .1.2.2.

Test:
50958:dchwalis admin$ grep 'revision 1\.2\.2$' test.txt
revision 1.2.2
50958:dchwalis admin$ grep '^revision 1\.2\.2$' test.txt
revision 1.2.2
50958:dchwalis admin$ grep '^revision 1\.0$' test.txt
revision 1.0
50958:dchwalis admin$

So on Windows, I changed the EOL char to CR (native CVS EOL set) from CRLF, and now it works.

Perhaps the moral is: don't listen to Cygwin setup when it suggests Unix EOL chars when you are running Windows. Or don't run Windows.

Leave a Reply