Link to home
Start Free TrialLog in
Avatar of Terry Rogers
Terry RogersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Extract Proxy Server from Proxy PAC file in DOS BATCH File

I have a Proxy PAC file that occasionally has the final proxy in the file changed.

I am creating a simple batch script that needs to extract the current value from this file.

The current code reads each line and prints (print is just for testing at present):-

for /f "eol=; tokens=1 delims=," %%i in (\\qahweb02\c$\inetpub\wwwroot\ProxyPac\proxy.pac) do (  
echo i: %%i  
set name=%%i  
echo name: %name%) 

Open in new window


A sample output of this command:-

i:      else if (isInNet(host
name:
i:              return "DIRECT";
name:
i:      else if (isInNet(host
name:
i:              return "DIRECT";
name:
i:      //All other scenarios go to proxy.
name:
i:      else
name:
i:              return "PROXY myproxyserver.mydomain.com:8080";
name:
i:
name:
i: }
name:

Open in new window


I need to identify if the current line has the
return "PROXY 

Open in new window

string, and if it does set a variable to the remainder of that line without the final 2 digits, so I would effectively get a variable filled with myproxyserver.mydomain.com:8080.

I'm not familiar with BATCH scripting (Or scripting in general tbh!)

How best can this be achieved?
Avatar of Grant Brunton
Grant Brunton
Flag of New Zealand image

Does it need to be a DOS batch file or can it be powershell?
Avatar of Terry Rogers

ASKER

Ideally BATCH as a partial script has already been created, so just need something to drop in.
ASKER CERTIFIED SOLUTION
Avatar of Grant Brunton
Grant Brunton
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked perfectly.

Thank you. :)