我有一个文本文件(myurls.txt),其内容的网址如下列表:从Windows批处理文件解析URL
Slides_1: http://linux.koolsolutions.com/svn/ProjectA/tags/REL-1.0
Exercise_1: http://linux.koolsolutions.com/svn/Linux/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
现在我想分析这个文本文件中的for循环,使得每次迭代后(对于如采取从上述文件中的第一个URL),我有以下资料到不同的变量:
%i% = REL-1.0
%j% = http://linux.koolsolutions.com/svn/ProjectA
%k% = http://linux.koolsolutions.com/svn/ProjectA/tags/REL-1.0
一些实验后,我有以下的代码,但它仅适用(种),如果网址有相同数量的斜杠:
@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.>
)
显然,我需要使它更灵活,以便它可以处理任意的url长度。我很喜欢其他解决方案,例如使用Windows Script Host/VBscript,只要它可以在默认的Windows XP/7安装下运行即可。换句话说,我知道我可以在Windows上使用awk,grep,sed,python等,并完成工作,但我不希望用户除了安装标准的Windows以外,不得不安装任何东西。
感谢您的答复!事实上,没有确定项目的规则。事实上,这些URL甚至可能没有名称中的Project。例如,URL可以简单地为:http://linux.koolsolutions.com/svn/LinuxMaterial/tags/REL-1.0。唯一的形式是每个URL都有标题(如Slides_N或Exercise_N)并以/tags/REL-X.Y结尾。 – modest
@modest - 那是一个规则:-)谢天谢地,它也符合我实施的规则。我去掉最后2个路径组件来获得项目,这将对应于“/tags/REL-X.Y”。它看起来像你的问题已经回答。 – dbenham
是的,您的解决方案在任何情况下均可使用。非常感谢! – modest