Take the 2-minute tour ×

I'm trying to use the following regular expression in grep (searches for mixed case PNG files).


When I enter the command, my shell displays a > looking for more input.

I can use grep for some basic regular expressions, but I've never quite gotten the handle of using it with more advanced regular expressions.

FWIW, this is in Cygwin on Windows 7.

share|improve this question
Please give more details like example of text you're looking for with grep. –  Paweł Nadolski Oct 18 '10 at 7:32
Do you want to find all png's regardless how they are spelled? –  Nifle Oct 18 '10 at 9:26
@Nifle: no, I'd like to find any png's that have at least one capital letter in their path. Our deployment process forces all files to lowercase, so I need to ensure that any references to these files are all lowercase. –  Alan Oct 18 '10 at 17:05
Then you should just find all .pPnNgG files regardless how they are spelled/cased and rename them to $name.png , renaming a file that are already named $something.png wont make a difference. –  Nifle Oct 18 '10 at 20:41
@nifle: that actually won't help. I don't want to rename any files (our deployment procedure always uses lower case names) I should have wrote that I want to find any references to these mixed case names inside various code files, so I can ensure that no mixed case names get into our code-base. –  Alan Oct 18 '10 at 23:32
add comment

1 Answer

up vote 2 down vote accepted

You did not escape " character. Double backslash before will be replaced with single backslash and " is left not escaped. Either remove one backslash or add one.

Try this regular expression:

grep -i '^[0-9a-z _]\+\.png\([^0-9a-z]+\|$\)' file | grep -v '^[0-9A-Za-z _]\+\.\(png\|PNG\)\([^0-9A-Za-z]\|$\)'

It will match all lines containing from the beginning of the line:

  • at least on of characters 0-9 (range of 0, 1, ..., 9 characters), a-z ' ' (space), '_'
  • a dot (needs to be escaped with backslash, otherwise it will mean 'any single character')
  • 'png' (or 'Png', etc. because -i is added)
  • and not followed by any of 0-9 and a-z characters (or A-Z because -i is added).

-i - will disable case sensitivity

share|improve this answer
Thanks. I actually need the test to be case sensitive (looking for mixed case files in particular). I don't find to match on any png files that are all lowercase. –  Alan Oct 18 '10 at 17:06
Updaded command to exclude files with extension all lowercase or all uppercase. It should display files which have .png mixed case. Also allowed line to end just after file name. –  Paweł Nadolski Oct 18 '10 at 18:25
add comment

Your Answer


