我有一个包含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的文本文件中?
答案 0 :(得分:1)
这样做你想要的:
for /f "tokens=2 delims=/" %%a in ('findstr /L "Location:" lines.txt') do echo http://%%a/ > url.txt
请注意,您必须使用正确的文本文件名替换lines.txt
。
答案 1 :(得分:1)
这应该有效:
@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
)