parsing urls from windows batch file
Posted
by
modest
on Stack Overflow
See other posts from Stack Overflow
or by modest
Published on 2012-09-07T21:35:51Z
Indexed on
2012/09/07
21:37 UTC
Read the original article
Hit count: 212
vbscript
|batch-file
I have a text file (myurls.txt) whose contents are a list of URLs as follow:
Slides_1: http://linux.koolsolutions.com/svn/ProjectA/tags/REL-1.0
Exercise_1: http://linux.koolsolutions.com/svn/ProjectA/tags/REL-1.0
Slides_2: http://linux.koolsolutions.com/svn/oldproject/ProjectB/tags/REL-2.0
Exercise_2: http://linux.koolsolutions.com/svn/ProjectB/tags/REL-1.0
Exercise_3: http://linux.koolsolutions.com/svn/BlueBook/ProjectA/tags/REL-1.0
Now I want to parse this text file in a for loop such that after each iteration (for e.g. take the first url from the above file) I have the following information into different variables:
%i% = REL-1.0
%j% = http://linux.koolsolutions.com/svn/ProjectA
%k% = http://linux.koolsolutions.com/svn/ProjectA/tags/REL-1.0
After some experiment I have the following code but it only works (kind of) if the URLs have same number of slashes:
@echo off
set FILE=myurls.txt
FOR /F "tokens=2-9 delims=/ " %%i in (%FILE%) do (
@REM <do something with variables i, j and k.>
)
I am fine with other solutions like for e.g. using Windows Script Host/VBS script as long as it can run with a default Windows XP/7 installation. In other words, I know I can use awk, grep, sed, python, etc. for Windows and get the job done but I don't want the users to have to install anything besides a standard windows installation.
© Stack Overflow or respective owner