Page 1 of 1

remove quotes from url in .bat file

Posted: 07 Jun 2018 10:25
by linuxteche
Hi,

I am trying to remove a double quotes from a URL but I am unable to remove it

I tried the following code and more things but I am not able to remove the double quotes from the url. Could you please help me on how to remove the double quotes from url.

Also the url is something like this and the same gets reflected in sample.out, this is the url that comes from an application

Code: Select all

"https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576" 
The FreeText in the does not get the url without quotes. I want the FreeText (in bold) to have the url without quotes.

Code: Select all

@echo off &setlocal
setlocal enabledelayedexpansion
set "PPI=C:\PPI"
echo "%AnalysisDeepLink%" >> E:\sample.out
set "ADL=%AnalysisDeepLink%"
rem set ADL1=!ADL:~1,-1!
rem echo.%ADL1%

rem set ADL=%ADL:"=%
rem echo %ADL%


rem for /f "useback tokens=*" %%a in ('%ADL%') do set str=%%~a
rem echo.%ADL%

echo %ADL% >> E:\sample.out

"%PPI%\ppi.exe" -c "%PPI%\ppi4vce.conf" -e "Domain=dummy;OriginSeverity=MAJOR;[b]FreeText[/b]=%ADL%"  -w "%PPI"


Re: remove quotes from url in .bat file

Posted: 07 Jun 2018 14:15
by Squashman
All three of these work for me.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set ADL="https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576"

set "ADL1=%ADL:~1,-1%"
echo !ADL1!

set "ADL1=%ADL:"=%"
echo !ADL1!


for %%G in (%ADL%) do set "ADL1=%%~G"
echo !ADL1!
output

Code: Select all

C:\BatchFiles\quotes>quotes.bat
https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576
https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576
https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576

Re: remove quotes from url in .bat file

Posted: 07 Jun 2018 19:34
by linuxteche
Thanks for your reply Sqashman. I too get the same.

But this url comes from another application, so I refer to that url as

Code: Select all

echo "%AnalysisDeepLink%" >> E:\sample.out
I could see the output in the sample.out as the url with double quotes

So, when I try the other codes, I am expecting the the double quotes removed but its not happening. In fact the output from

Code: Select all

echo ADL1 >> E:\\sample.out
is not even getting updated.

Code: Select all

set "ADL=%AnalysisDeepLink%"
set "ADL1=%ADL:~1,-1%"
echo !ADL1!
echo ADL1 >> E:\\sample.out

Re: remove quotes from url in .bat file

Posted: 07 Jun 2018 20:06
by Squashman
Variable name is irrelevant. Still comes out the same for me.

Code: Select all

@echo off
setlocal enabledelayedexpansion
set AnalysisDeepLink="https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576"

set "ADL1=%AnalysisDeepLink:~1,-1%"
echo !ADL1!

set "ADL1=%AnalysisDeepLink:"=%"
echo !ADL1!


for %%G in (%AnalysisDeepLink%) do set "ADL1=%%~G"
echo !ADL1!
Output

Code: Select all

https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576
https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576
https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576

Re: remove quotes from url in .bat file

Posted: 08 Jun 2018 02:58
by penpen
linuxteche wrote:
07 Jun 2018 19:34

Code: Select all

echo !ADL1!
echo ADL1 >> E:\\sample.out
You noticed the flaw you made?
(Missing '!'-characters.)
Squashman wrote:
07 Jun 2018 20:06

Code: Select all

for %%G in (%AnalysisDeepLink%) do set "ADL1=%%~G"
This line shouldn't work (because of the '?' character in the link - at least under my windows 10).

"test.bat":

Code: Select all

setlocal enabledelayedexpansion
set AnalysisDeepLink="https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576"
set "ADL1="
for %%G in (%AnalysisDeepLink%) do set "ADL1=%%~G"
echo !ADL1!
Result:

Code: Select all

Z:\>test
ECHO ist ausgeschaltet (OFF).
penpen

Re: remove quotes from url in .bat file

Posted: 08 Jun 2018 07:17
by Squashman
I was using Windows 10 when I was testing my code last night.

Re: remove quotes from url in .bat file

Posted: 08 Jun 2018 07:30
by penpen
You haven't reinitialized ADL1, so you are echoing an older value.

penpen

Re: remove quotes from url in .bat file

Posted: 08 Jun 2018 08:52
by Squashman
penpen wrote:
08 Jun 2018 07:30
You haven't reinitialized ADL1, so you are echoing an older value.

penpen
You are correct. That needs to be changed to a `FOR /F`

Code: Select all

@echo off
setlocal enabledelayedexpansion
set AnalysisDeepLink="https://dummy.com:443/en.server/html/next/index.jsp?dl=dash&envId=00001&planId=0001&Monitoring=false&FilterId=01&Start=1527782791576&End=1528387591576"

set "ADL1="
set "ADL1=%AnalysisDeepLink:~1,-1%"
echo !ADL1!

set "ADL1="
set "ADL1=%AnalysisDeepLink:"=%"
echo !ADL1!

set "ADL1="
for /f "delims=" %%G in (%AnalysisDeepLink%) do set "ADL1=%%~G"
echo !ADL1!