我有一个文本文件,其中包含一些网址:
http://www.amazon.com/Armed-Struggle-History-Richard
http://www.amazon.com/Irish-Freedom-History-Nationalism-Ireland/
http://www.amazon.com/Armed-Struggle-History-Richard-English
http://www.amazon.com/Ernie-OMalley-Intellectual-Richard
http://www.amazon.de/Ernie-OMalley-Intellectual-Richard
http://www.amazon.uk/Ernie-OMalley-Intellectual-Richard
http://www.amazon.de/Irish-Freedom-History-Nationalism-Ireland/
我想在运行批处理文件时选择所有网址都有amazon.com并将结果设为:
将/ amazon.com/之后的所有标题放在[B] [/ B]中并删除 - 并替换空格 然后将网址放在[link] [/ link]
中[B]
Armed Struggle History Richard
[/B]
[link]
http://www.amazon.com/Armed-Struggle-History-Richard
[/link]
[B]
Irish Freedom History Nationalism Ireland
[/B]
[link]
http://www.amazon.com/Irish-Freedom-History-Nationalism-Ireland
[/link]
[B]
Armed Struggle History Richard English
[/B]
[link]
http://www.amazon.com/Armed-Struggle-History-Richard-English
[/link]
[B]
Ernie OMalley Intellectual Richard
[/B]
[link]
http://www.amazon.com/Ernie-OMalley-Intellectual-Richard
[/link]
答案 0 :(得分:1)
您可以从这个批处理文件开始:
@echo off
Title Batch Hyperlink Maker
Set "file=urls.txt"
Set "KeyWord=amazon"
Set "OutputFile=OutputFile.txt"
If exist "%OutputFile%" Del "%OutputFile%"
setlocal enabledelayedexpansion
@for /f "delims=" %%a in ('Type "%File%" ^| find /I "%KeyWord%"') do (
@for /f "tokens=3 delims=/" %%b in ("%%a") do (
Call :Replace %%b
echo [B]
echo !Title!
echo [/B]
echo(
echo [link]
echo %%a
echo [/link]
echo(
(
echo [B]
echo !Title!
echo [/B]
echo(
echo [link]
echo %%a
echo [/link]
echo(
)>>"%OutputFile%"
)
)
Start "" "%OutputFile%" & pause >nul & exit
::*******************************************************************
:Replace <String>
Set "Title=%1"
Set "String=-"
Set "NewString= "
Rem replace the dash "-" by a space " " into a String
Call Set "Title=%%Title:%String%=%NewString%%%"
Set "String=.html"
Set "NewString="
Rem replace the string ".html" by a "" into a String
Call Set "Title=%%Title:%String%=%NewString%%%"
Exit /b
::*******************************************************************