1

I can't seem to write certain characters (inverted question marks, fancy single quote marks, ampersands) to a text file, and then to search that file for those characters. For example the following findstr doesn't find the upside down question mark item in .txt:

 @echo off
 echo "Cato Event - GO Beyond GDP. What Really Drives the Economy¿">c:\test.txt
 findstr /I /N /C:"Cato Event - GO Beyond GDP. What Really Drives the Economy¿" c:\test.txt 
 pause

 ::chcp 1254

I've tried with various chcp commands also to no avail. Any help appreciated.

RKO
  • 161
  • 10

1 Answers1

0

That is a known issue with FINDSTR - Some characters provided on the command line with ANSI byte codes > 127 are transformed into a different character by FINDSTR, prior to doing the search, which causes the search to fail.

The solution is to put the search string(s) in a file and use the /L and /G options.

See the section titled "Character limits for command line parameters - Extended ASCII transformation" at What are the undocumented features and limitations of the Windows FINDSTR command?

The only other option (assuming you want to stick with native batch commands) is to use FIND instead. It has much less functionality, but it does not have the character translation issue, and I believe it should work for your simple literal search.

find /I /N "Cato Event - GO Beyond GDP. What Really Drives the Economy¿" c:\test.txt 

The line numbers at the beginning of each matching line will look like [123] instead of 123:.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Thanks. Here's your comments incorporated. @echo off echo /c:>c:\mssucks.txt echo "Cato Event - GO Beyond GDP. What Really Drives the Economy¿">>c:\mssucks.txt findstr /I /L /G:c:\mssucks.txt c:\mssucks.txt pause For large datasets it's verrrry slow. Any links - tips on other ways to ping a folder full of files against a list of filenames, taking into account ANSI codes >127? – RKO May 25 '16 at 21:36
  • Thanks. Just as slow, but at least it works. Findstr still threw out strange errors even when putting the search string(s) into a file. Working and slow beats not-working and slow. rko – RKO May 26 '16 at 00:59