batch-file - 如何在命令提示符下修剪字符串?

标签 batch-file cmd

我的目录中有很多快捷方式网址。

C:\Users\Owner\Desktop\ReadItLaters>dir *.url /b
aaa.url
bbb.url
ccc.url

...

zzz.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

味道不错。但我想获取没有“URL=”的 url 字符串。

我希望这样输出。

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=”替换为空?

最佳答案

您可以使用子字符串,跳过字符串中的前 4 个字符:%_url:~4%

<强> /

for /f %%i in ('type *.url^|find "URL="')do set "_url=%%~i" && call echo/%_url:<b>~4</b>%

<强>

for /f %i in ('type *.url^|find "URL="')do set "_url=%~i" && call echo/%_url:<b>~4</b>%

关于batch-file - 如何在命令提示符下修剪字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63424043/

相关文章:

windows - 完成命令行后关闭程序

c# - C# 控制台批处理应用程序中的最佳计时器方法

Windows x64 & "parenthesis in path"批处理文件问题

python - 将 cmd 命令的过滤输出存储在变量中

linux - 编写 linux 命令脚本来修改文件中的数据

windows - 将带有开关的参数传递给批处理文件

file - 选择多个文件, "send to"batch.cmd,让batch.cmd对选定的文件运行一个程序

c++ - 在 Windows 8 上使用 MinGW 在 cmd 中编译 C++

windows-7 - 单击 更改时间。 window 里的 bat

java cmd 命令适用于 Windows,但不适用于 centOS