The environment is WindowsXP (possibly upgrading to Windows7 soon). I am allowed to run scripts but NOT allowed to install tools.


Output matched lines from a Log.txt file in same order as list of search terms (Tokens.txt, one token per line), which have been extracted from StartingList.txt (a text listing of filepaths, available as %1 to a batch file).

PROBLEMS: (and work-arounds)

Method1 below: Command line FindStr changes the order (vs order of the listed search terms). A work-around is to use a FOR loop:

Method2 below: Batch FOR loop with FindStr is very slow and changes some characters (outside the range of 32 to 126, command line fonts and character sets may not agree with the underlying Windows Unicode support - see question 157225 for more info on char aspects). A workaround is to ban use of characters outside the 'safe' range of 32 thru 126, or run a tail-end 'find and replace' on any changed characters.

POSSIBLE SOLUTIONS: (This is where I need help please ...)

An equivalent unicode-aware VBScript or JScript (possibly using JREPL too) would solve the slow speed and support all Unicode characters.

An example of a functionally equivalent FOR loop in these scripting languages would help, please.

The closest JREPL methods are by dbenham at question 1052645 and at: http://www.dostips.com/forum/viewtopic.php?p=39534#p39534

Example StartingList.txt:

D:\Pics\2005-03-27 Bristol\2005-03-27 DSC_0016#.JPG  
D:\Pics\2005-03-26 Brighton\2005-03-26 DSC_0014#^{!k¿m.JPG  
D:\Pics\2005-03-26 London\2005-03-26 DSCN0015#.JPG  
D:\Pics\2005-03-28 Bath\2005-03-30 _DSC0019#.JPG  
D:\Pics\2005-03-28 Bath\2005-03-29 P01_0018#.JPG  

Example Tokens.txt:


Example Log.txt:

F:\Pics\Edited\2005-03-28 Bath\2005-03-30 _DSC0019#.JPG  
F:\Pics\Edited\2005-03-28 Bath\2005-03-29 P01_0018#.JPG  
F:\Pics\Edited\2005-03-28 Bath\2005-03-28 DSC_0017#.JPG  
F:\Pics\Edited\2005-03-27 Bristol\2005-03-27 DSC_0016#.JPG  
F:\Pics\Edited\2005-03-26 London\2005-03-26 DSCN0015#.JPG  
F:\Pics\Edited\2005-03-26 Brighton\2005-03-26 DSC_0014#^{!k¿m.JPG  

Example StartingList(updated).txt:

F:\Pics\Edited\2005-03-27 Bristol\2005-03-27 DSC_0016#.JPG  
F:\Pics\Edited\2005-03-26 Brighton\2005-03-26 DSC_0014#^{!k¿m.JPG  
F:\Pics\Edited\2005-03-26 London\2005-03-26 DSCN0015#.JPG  
F:\Pics\Edited\2005-03-28 Bath\2005-03-30 _DSC0019#.JPG  
F:\Pics\Edited\2005-03-28 Bath\2005-03-29 P01_0018#.JPG  

Method 1:

type nul >%1
findstr /G:Tokens.txt Log.txt >%1(updated).txt

Method 2:

setlocal enableDelayedExpansion
type nul >%1
for /F "tokens=*" %%i in (Tokens.txt) do (
    findstr /C:"%%i" Log.txt >>%1(updated).txt

Method 3:

Ideally, a solution something like this, possibly using JREPL, passing in search parameters as a text list, perhaps using a pipe in or out, possibly to another JREPL? The solutions to question 850183 seem close, but my pensioner-brain cannot bridge the gap - apologies for my poor attempt:

Otherwise a pure JScript or VBScript example would help, please.

::method3 [pseudo Jscript in square brackets is where I need help please]
type nul >%1
Call jrepl "[Read in Tokens.txt, match each token IN LISTED ORDER]" "[if (token==match, output matched line)]" /jmatch /jbeg "[cnt]" /f Log.txt /o >%1(updated).txt
  • What characters are changed when you use the for loop? – DavidPostill Mar 18 '16 at 12:33
  • Method 2 works for me, using your example log.txt and tokens.txt. – DavidPostill Mar 18 '16 at 12:46
  • The inverted question mark is a good one to look at (Alt+168). It changes to the umlaut (superscript double dots) on my WinXP. Also, Method2 takes a good hour or so to run through a typical log file of image filepaths. Yikes! – TuesusMalnex Mar 18 '16 at 12:53
  • On the other hand, Method1 is done in the blink of an eye, but outputs in the default order of the FindStr function. – TuesusMalnex Mar 18 '16 at 12:56
  • 1
    Alt+168 is preserved here (Windows 7). I can't think of an obvious way to fix method 1 or method 2 speed. I suspect dbenham is required to answer method 3 if he wanders past and sees the question. – DavidPostill Mar 18 '16 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.