2015-04-15 56 views
0

我有一個包含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

凡將是批處理文件運行嗎? – Antxon

回答

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 
) 
1

這你想要做什麼:

for /f "tokens=2 delims=/" %%a in ('findstr /L "Location:" lines.txt') do echo http://%%a/ > url.txt 

注意你將與你的文本文件的正確名稱,以取代lines.txt

相關問題