Batch file 如何在命令提示符中修剪字符串?
我在一个目录中有很多快捷URLBatch file 如何在命令提示符中修剪字符串?,batch-file,cmd,bat,command-line,Batch File,Cmd,Bat,Command Line,我在一个目录中有很多快捷URL C:\Users\Owner\Desktop\ReadItLaters>dir *.url /b aaa.url bbb.url ccc.url ... zzz.url 我想获取那些url。 所以我写了这样的命令 for %i in (*.url) do @type "%i" | find "URL=" URL=https://www.example.com/aaa.html URL=https://www.
C:\Users\Owner\Desktop\ReadItLaters>dir *.url /b
aaa.url
bbb.url
ccc.url
...
zzz.url
我想获取那些url。
所以我写了这样的命令
for %i in (*.url) do @type "%i" | find "URL="
URL=https://www.example.com/aaa.html
URL=https://www.example.com/bbb.html
URL=https://www.example.com/ccc.html
...
URL=https://www.example.com/zzz.html
https://www.example.com/aaa.html
https://www.example.com/bbb.html
https://www.example.com/ccc.html
...
https://www.example.com/zzz.html
这样输出
for %i in (*.url) do @type "%i" | find "URL="
URL=https://www.example.com/aaa.html
URL=https://www.example.com/bbb.html
URL=https://www.example.com/ccc.html
...
URL=https://www.example.com/zzz.html
https://www.example.com/aaa.html
https://www.example.com/bbb.html
https://www.example.com/ccc.html
...
https://www.example.com/zzz.html
味道很好。但我想获得不带“url=”的url字符串
我希望这样输出
for %i in (*.url) do @type "%i" | find "URL="
URL=https://www.example.com/aaa.html
URL=https://www.example.com/bbb.html
URL=https://www.example.com/ccc.html
...
URL=https://www.example.com/zzz.html
https://www.example.com/aaa.html
https://www.example.com/bbb.html
https://www.example.com/ccc.html
...
https://www.example.com/zzz.html
如何替换“URL=”以清空?使用
for/f
循环来处理行:
for /f "tokens=2 delims==" %%a in ('type *.url 2^>nul^|find "URL="') do @echo %%a
或者一个位节省器(如果URL包含=
)
有关详细信息,请参见获取/?
(注意:这是批处理文件语法。如果要直接在命令行上使用它,请将每个
%%
替换为单个%%
)您应该能够获得多个URL文件的信息,而无需为循环嵌套两个。您可以利用FindStr
的功能直接搜索多个文件
:
@For/F“Tokens=1*Delims==”%%G In(“%”“%\uuuuu AppDir\uuuuuu%findstr.exe”/IR“^URL=http”*.URL“2>NUL”)Do@Echo%%H
:
For/F“Tokens=1*Delims==%G In(“%”“%\uuuuu AppDir\uuuuu%findstr.exe”/IR“^URL=http”*.URL“2>NUL”)Do@Echo%H
您可以使用子字符串,跳过字符串中的前4个字符:%\u url:~4%
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
/
对于/f%%i in('type*.url^ | find“url=“”)设置“\u url=%%~i”&调用echo/%\u url:~4%
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
对于/f%i in('type*.url^ find“url=”)设置“\u url=%i”&调用echo/%\u url:~4%
- 进一步阅读:
[√]
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
[√]
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
[√]
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
[√]
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
[√]
for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:~4%
for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:~4%
此命令对我来说很容易理解。感谢您的回复!