Dear Sir or Madam:
I cannot discover what I am doing wrong here, so perhaps you could correct
my error.
I have a file, named bp_fs.h. It has windows type line endings, and is a
text file. The first lines look like
/* (c) Copyright 2011
$Header:
*/
/*
----------------------------------------------------------------------------
//
// Filename: bp_fs.h
And here is what I am trying to do:
1) Find all files
a. Of type "file"
b. Whose name is bp_fs.h (usually this would be "ends with a .c or a
.h", but I was trying to debug)
i. Where
the first 5 lines do NOT contain
ii. The
text $Header: $ Please note that there are optional characters
after the colon, before the final $
2) If this is all true, then output the name of the file.
Now to the script I run
find . -type f -name bp_fs.h ! -exec sh -c "cat {} | head -n 5 | grep -q
'\$Header:.*\$'" \; -print
The problem is that it does not output the name of the file in question.
If I run this script instead, I get the following output
Kirk@kirk-xp960 /cygdrive/c/code
$ find . -type f -name bp_fs.h ! -exec sh -c "cat {} | head -n 5 | grep
'\$Header:.*\$'" \; -print
$Header:
Kirk@kirk-xp960 /cygdrive/c/code
The difference is that grep does not have the -q, so it correctly outputs
the matched line. Only, I do not believe that I should have a match.
In fact, if I do the following (these were all pasted from the screen) in
order
Kirk@kirk-xp960 /cygdrive/c/code
$ find . -type f -name bp_fs.h ! -exec sh -c "cat {} | head -n 5 | grep -q
'\$Header:.*\$'" \; -print
Kirk@kirk-xp960 /cygdrive/c/code
$ find . -type f -name bp_fs.h ! -exec sh -c "cat {} | head -n 5 | grep
'\$Header:.*\$'" \; -print
$Header:
Kirk@kirk-xp960 /cygdrive/c/code
$ grep '\$Header:.*\$' bp_fs.h
Kirk@kirk-xp960 /cygdrive/c/code
$ grep '\$Header:.*' bp_fs.h
$Header:
Kirk@kirk-xp960 /cygdrive/c/code
The last two times, I was just trying the grep by itself. I think this
experiment shows that grep does not find a match of $Header.....$, mostly
because there is not one, but somehow I am getting a match on the
complicated find + sh + grep combination. I am sure I am missing
something, but I do not know what.
Are you able to shed some light on this?
Kind regards,
Kirk
P.S.
Kirk@kirk-xp960 /cygdrive/c/code
$ uname -a
CYGWIN_NT-5.1 kirk-xp960 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin
Kirk@kirk-xp960 /cygdrive/c/code
$ grep --version
GNU grep 2.6.3
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.