I have a xml files filles with tabs and spaces. I am trying to search for a string in this file. File is something like below. I am trying to search for </ViewSettings> and this surrounded by tabs and spaces.
<ViewSettings>
<Location>
<X>0</X>
<Y>0</Y>
</Location>
</ViewSettings>
<WorkspaceName="FREE_UST_BETA_UA" PAth="\\mktxindfs\data_configuration\FREE_BETA" IsAdmin="false" />
</Workspaces>
I have the code below
echo off
setlocal enabledelayedexpansion
for %%X in (C:\add\WorkspaceXML\Workspaces.xml) do (
set "reference=</ViewSettings>"
for /f "delims=" %%T IN (%%X) do (
set output=%%T
echo output:!output!
if !output!==!reference! echo found reference.....
)
)
It does not print “found reference”
Thanks
Have you considered building your batch file off of
findstrinstead? This command would tell you if the string was in the file by reporting the filename.EDIT
If you use
findstr /N /O ...instead, you can get the line number and offset of the match(es), maybe that will be of more use to you. The output in your case above would beEDIT 2
Proper offset added above thanks to dbenham. Not sure if the offset is still of use to you, but to get both values in vars, try this:
This just displays the vars for you of course, but you can set them as needed.