Expert script (.bat) writers help needed (strip double-quote from string)

J

James

Won't bore you with all the background, but URGENTLY need
suggestions on how I can complete the "REM ## Strip any
double-quotes from %%j and %%k" bit (in other words, want
to remove all double-quotes from a string within a batch
file using only the tools available "native" to WinXP).

The script below running on WinXP Pro. (If you don't
understand the script below, please do not both to ask me
to explain it).



@echo off

for /D %%I in (data*) do (

echo Checking "%%~I"

if exist "%%~I\index.fil" (
for /F "tokens=1,2* usebackq" %%i in ("%%
~I\index.fil") do (
if %%i == Description (
REM ## Strip any double-quotes from %%j and %%k
echo Description "%%j %%k"
)
)
)
)
 
J

James

Unfortunately, this only removes "surrounding" double-
quotes. Ie, if string were to contain quotes within the
text ("Hello "cruel" world"), only the outside quotes are
removed with the inclusion of a ~

:( Nice try thou
 
J

James

Thank you David, your suggestions sparked the idea which
lead me to a solution!! And an elegant one at that.

Basically combined the idea of using a for loop with the %%
~ operation (see the for %%s). Didn't think of this
earlier because of the old DOS limitation of not being
able to nest for-next loops (old habits die hard). Only
downfalls are (1) had to trim one leading space (overcome
by adding [start]set TempVar=!TempVar:~1![end] after the
loop, so no biggy), and (2) won't handle mistyped words
like [start]I don"t like green eggs and ham[end], but a
random sampling of our data showed this not to be a
problem (it's lines like [start]"Goodbye "cruel"
world!"[end] which caused all the grief).

So here's the final outcome...

@echo off

for /D %%I in (data*) do (

echo Checking "%%~I"

if exist "%%~I\index.fil" (
for /F "tokens=1,2* usebackq" %%i in ("%%
~I\index.fil") do (
if %%i == Description (
set TempVar=
for %%s in (%%j %%k) do set TempVar=!TempVar! %%~s
set TempVar=!TempVar:~1!
echo Description "!TempVar!"
)
)
)
)

Thanks again.
James
-----Original Message-----
I thought the for command would help but haven't found a
way to specify " as a delimiter. And a search of several
hundred posts using the delims command didn't find anyone
who has tried.
This is one that doesn't work as it assumes no delimiters
for /f "tokens=1,2,3 delims=""" %m in (""dog" cat") do echo %m and %n

^" doesn't help.

Therefore,
1. Write a vbs/jscript script (I've attached one that
search and replaces files - you can modify it to write the
result to the console).
ReplaceRegExp Filename SearchString ReplaceString. Quotes
are required for spaces. Use 0xnn for wierd characters.
Wildcard list is below..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top