I am trying to write a Windows batch file that will look through a specific html index file that looks something like this (simplified)
<a href=emergency.htm>Emergency Calls</a><br>
<a href=EmeRgency.htm>Emergency Calls</a><br>
<a href=Emergency.htm>Emergency Calls</a><br>
<a href=EMERGENCY.htm>Emergency Calls</a><br>
<a href=E911.htm>Emergency Calls</a><br>
<a href=e911.htm>Emergency Calls</a><br>
and print all links whose filenames contain any uppercase letters so that they may be corrected not to so include any.
The following works in unix:
$ grep -v '^<a href=[^A-Z]*\.htm' helpindex.htm
<a href=EmeRgency.htm>Emergency Calls</a><br>
<a href=Emergency.htm>Emergency Calls</a><br>
<a href=EMERGENCY.htm>Emergency Calls</a><br>
<a href=E911.htm>Emergency Calls</a><br>
(the -v reverses the match)
But using the UnxUtils grep under Windows, which is a direct port of unix grep, I can't come up with a way of quoting the regex that works. This would be necessary to use it in a batch file. I've tried ', " with no joy and also the -E switch. Is there any way to do this using this particular toolset?
@janos led me to the findstr command in Windows but it still doesn't work. Looking at the findstr help I see:
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]] strings [[drive:][path]filename[ ...]]
...
/V Prints only lines that do not contain a match. ...
/C:string Uses specified string as a literal search string. ...Use spaces to separate multiple search strings unless the argument is prefixed with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or "there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for "hello there" in file x.y.
However, this doesn't work either:
C:\home\sftp>findstr /V /C:"^<a href=[^A-Z]*\.htm" helpindex.htm
<a href=emergency.htm>Emergency Calls</a><br>
<a href=EmeRgency.htm>Emergency Calls</a><br>
<a href=Emergency.htm>Emergency Calls</a><br>
<a href=EMERGENCY.htm>Emergency Calls</a><br>
<a href=E911.htm>Emergency Calls</a><br>
<a href=e911.htm>Emergency Calls</a><br>
Either findstr is garbage or there is some subtle difference from grep.