Solved findstr reads txt files created by hand but not log files

April 10, 2013 at 08:10:13
Specs: Windows 7
I have a batch file that reads an XML file for the string "<team_id>0</team_id>" then writes the file name to a results.txt file. This works great with any file I create but I have a directory full of XML files that a program created that I need to search for that string. I can copy the contents of the XML file that was auto-generated by the software and paste it into a test.xml file and everything works fantastic. Any ideas or help would be greatly appreciated? Here is my script:

findstr /L /M "<team_id>0</team_id>" c:\remoteupdate\ie8_push\logs\* > results.txt
if %errorlevel%==0 (
echo Success logged files into results.txt
) else (
echo No matches found
)
pause


See More: findstr reads txt files created by hand but not log files

Report •


✔ Best Answer
April 10, 2013 at 18:46:21
It may be a "unicode thing". To determine, EDIT one of the files with the binary switch:
EDIT /70 nnnn.XML
and look for "spaces" (actually char zero) between each of the letters. (If you move the cursor over these, they will show "value 0" down in the lower right corner).
The findstr "workaround" would be:
findstr /r /i /c:"<.t.e.a.m._.i.d.>.0.<./.t.e.a.m._.i.d.>"
so the wildcard dots would soak up those zeros.
Powershell can readily handle unicode, I'm sure, but I don't know it! :-(


#1
April 10, 2013 at 09:19:45
Some generated files have non-standard line breaks.

Case in point: ipconfig with it's:
0D 0D 0A

By pasting it into a file you're probably losing the goofy breaks.

HTH

=====================
M2 Golden-Triangle


Report •

#2
April 10, 2013 at 11:33:34
Unfortunately, that would kind of cancel out the benifit since I have over a hundred to go through. Can you think of another way to make this work?

Report •

#3
April 10, 2013 at 12:31:48
How big are the files?

If under about 30KB I have a util.

Otherwise we'd dig for a util from back in the misty past such as unix2DOS or whatnot.

This presupposes that the line breaks ARE the prob.

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
April 10, 2013 at 13:01:31
You could try a different language. As a bonus, it'll correctly parse the DOM, which your batch does not.
Powershell:
Get-ChildItem * | ForEach-Object { 
  if (([xml](Get-Content $_)).SelectNodes("//team_id") `
     | Where-Object { $_.'#text' -eq "0" }) { $_ } 
}

How To Ask Questions The Smart Way


Report •

#5
April 10, 2013 at 16:57:42
I am having this issue on several different types of log files. The some are under 30K others are 100+. I'll play with the powershell idea when I get in tomorrow. Unfortunatly, I don't have much experience in powershell but I am sure I'll figure it out. I'll let you know!

Report •

#6
April 10, 2013 at 17:45:43
Post the findstr code that's failing.

And ZIP up a few of the small files.

=====================
M2 Golden-Triangle


Report •

#7
April 10, 2013 at 18:46:21
✔ Best Answer
It may be a "unicode thing". To determine, EDIT one of the files with the binary switch:
EDIT /70 nnnn.XML
and look for "spaces" (actually char zero) between each of the letters. (If you move the cursor over these, they will show "value 0" down in the lower right corner).
The findstr "workaround" would be:
findstr /r /i /c:"<.t.e.a.m._.i.d.>.0.<./.t.e.a.m._.i.d.>"
so the wildcard dots would soak up those zeros.
Powershell can readily handle unicode, I'm sure, but I don't know it! :-(

Report •

#8
April 11, 2013 at 08:22:44
Thanks nbrane!! That worked perfectly. Thank you!

Report •

#9
April 11, 2013 at 08:47:16
Or morph them into text:

type some.log > some.txt

or batch a bunch:

:: ===== script starts here ===============
::
:: uni2txt.bat 2013-04-11 22:43:16.56
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b *.log') do (
type %%a > %%~Na.txt
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •


Ask Question