Batch file 将文本文件中一行的子字符串存储到单独的文本文件中

Batch file 将文本文件中一行的子字符串存储到单独的文本文件中,batch-file,Batch File,我有一个包含5行的文件: Resolving portal... ip_address Connecting to portal|ip_address|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://portal1.com/portal [following] Connecting to portal1.com|ip_address|:80... connected. 如何

我有一个包含5行的文件:

Resolving portal... ip_address
Connecting to portal|ip_address|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://portal1.com/portal [following]
Connecting to portal1.com|ip_address|:80... connected.

如何使用批处理脚本保存字符串
http://portal1.com/
(第4行)到名为url.txt的文本文件?

这是您想要的:

for /f "tokens=2 delims=/" %%a in ('findstr /L "Location:" lines.txt') do echo http://%%a/ > url.txt
注意:您必须用文本文件的正确名称替换
lines.txt

这应该有效:

@ECHO OFF
SETLOCAL enabledelayedexpansion
FOR /F "tokens=*" %%a IN (yourtextfile.txt) DO (
    SET line=%%a
    IF "!line:~0,10!"=="Location: " SET location=%%a
)
FOR /F "tokens=2 delims=/" %%l IN ("%location%") DO (
    ECHO http://%%l/ > url.txt
)

批处理文件在哪里运行?