我有一个文本文件,其中包含一些urls,如:
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/我希望在运行批处理文件时,选择所有urls都有amazon.com并取得以下结果:
将所有标题放在/ amazon.com/ in B之后,然后删除并替换空间,然后将urls放在链接中
[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]发布于 2017-11-02 16:01:54
您可以从以下批处理文件开始:
@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
::*******************************************************************https://stackoverflow.com/questions/47040636
复制相似问题