China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 06:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to split a text file so each line becomes a new text file View 930 Replies 5
Original Poster Posted 2010-06-14 17:31 ·  中国 浙江 杭州 西湖区 电信
新手上路
Credits 11
Posts 8
Joined 2010-06-10 23:26
16-year member
UID 168569
Gender Male
Status Offline
Split text.txt like this
http://www.qidian.com/book/1510857.aspx
http://www.qidian.com/book/1518407.aspx
http://www.zhulang.com/130808/index.html
http://www.17k.com/book/65798.html
http://book.zongheng.com/book/39679.html
and make it become text like this
1.txt
http://www.qidian.com/book/1510857.aspx
2.txt
http://www.qidian.com/book/1518407.aspx
……
------------------------------------------------------------------
Or split it into text like this
1.txt

URL=http://www.qidian.com/book/1510857.aspx
2.txt

URL=http://www.qidian.com/book/1518407.aspx
……

What I want is to convert the list of links in the text into individual *.URl files, so it's convenient to import into the browser

Asking the experts here, I can use for to extract each line, but I don't know how to output it to text
Floor 2 Posted 2010-06-14 20:15 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
1, there must be no blank lines in the text:
@echo off
for /F "tokens=1* delims=:" %%a in ('findstr /n .* text.txt') do (
set "b=%%b"
setlocal enabledelayedexpansion
>>%%a.txt echo.!b!
Endlocal)
2, there must be no blank lines in the text:
@echo off
for /F "tokens=1* delims=:" %%a in ('findstr /n .* text.txt') do (
set "b=%%b"
setlocal enabledelayedexpansion
>>%%a.txt echo.
>>%%a.txt echo.URL=!b!
Endlocal)


[ Last edited by Hanyeguxing on 2010-6-15 at 09:18 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
keeds +1 2010-06-15 23:45
Floor 3 Posted 2010-06-14 23:15 ·  中国 浙江 杭州 电信
新手上路
Credits 11
Posts 8
Joined 2010-06-10 23:26
16-year member
UID 168569
Gender Male
Status Offline
Originally posted by Hanyeguxing at 2010-6-14 20:15:
1, There must not be blank lines in the text:
@echo off
for /F "tokens=1* delims=:" %%a in ('findstr /n .* test.txt' do (
set "b=%%b"
setlocal enabledelayedexpansion
>>%%a.txt ...


What does the prompt “FINDSTR: Cannot open test.txt” mean?

I just started learning, I only know simple for loops, and I can't understand the rest at all
Floor 4 Posted 2010-06-15 05:16 ·  中国 台湾 台湾宽频通讯顾问股份有限公司
初级用户
★★
Credits 68
Posts 64
Joined 2009-05-23 20:43
17-year member
UID 145803
Gender Male
Status Offline
Change your text.txt to test.txt, or change the Batch's test.txt to text.txt
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
keeds +1 2010-06-15 23:46
Floor 5 Posted 2010-06-15 11:53 ·  中国 浙江 杭州 电信
新手上路
Credits 11
Posts 8
Joined 2010-06-10 23:26
16-year member
UID 168569
Gender Male
Status Offline
Originally posted by pdanniel66 at 2010-6-15 05:16:
Change your text.txt to test.txt, or change the Batch's test.txt to text.txt


Haha, I didn't see it clearly and made a fool of myself
Floor 6 Posted 2010-06-15 11:55 ·  中国 浙江 杭州 电信
新手上路
Credits 11
Posts 8
Joined 2010-06-10 23:26
16-year member
UID 168569
Gender Male
Status Offline
It worked, many thanks to Hanyeguxing for solving the problem, and to pdanniel66 for the correction. I learned a bit more too, I'll go study what the commands do
Forum Jump: