Batch file to retrieve one line at a time and then loop through directories of files to find matches to each line

I have a file of keys and values and wish to step though each key and see if that key occurs at least once (or provide count) in at least one file.

First file looks like this:

"" : "hello world",
"lorem.ipsum" : "a quick brown fox",

and I want to sweep all .js files in subdirectories to see if "" is used and provide a count for that key; then take the next key "lorem.ipsum" and sweep all js files in subdirectories to see if it is used and then provide a count.

I get parts of the soltion working but do not get the whole thing working together at once. Challenges has veen findstr does not use /c for count and needing () to keep everything in order.

The outer part I cna get to iterate thourhg each of the lines of the string file...

for /f "skip=1 delims=:" %%a in (src/dict/strs_en.json) do (
    findstr /s %%a c:\foo\bar\my\code\*.js

but internally I need something more like an example that was gien elsewhere in stackoverflow:

for /F "delims=" %G in ('findstr /I /S /M "" "%CD%\*.js"') do @find /I /C "home." "%~G" | findstr /V /R "^$"

where "" is really my %%a

In the end, desired output would be either (I just want ot know what is used and what is not used)

""  2
"lorem.ipsum" 1
""  0


- file1.js
- file2.js

- file3.js


- file2.js
- file3.js

1 answer

  • answered 2018-03-13 20:49 Compo

    Does the output in output.log give you something you can work with after running this batch file:

    @(For /F UseBackQDelims^=^" %%A In ("src\dict\strs_en.json") Do @(
        Echo="%%A" & FindStr/SMC:"%%A" C:\foo\bar\my\code\*.js & Echo=))>output.log