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-06-27 14:43
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help!! How to concatenate multiple lines in a text into one line View 3,397 Replies 25
Floor 16 Posted 2007-02-04 02:09 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 180
Posts 68
Joined 2006-12-21 23:44
19-year member
UID 74192
Gender Male
From China
Status Offline
After merging 1000 or more lines, how to turn them back into the original individual lines??
for /f "delims=;????" %i in (merged.txt) do echo ????? >new.txt
?????
Floor 17 Posted 2007-02-04 03:35 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Brother on floor 16, written with VBS, please make sure there are no ";" symbols in the source file.

set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("b.txt")
s=file.readall
file.close
set file=fso.createtextfile("c.txt")
file.write replace(s,";",vbcrlf)
file.close
msgbox "Restore successful",4096
Floor 18 Posted 2007-02-04 08:34 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 180
Posts 68
Joined 2006-12-21 23:44
19-year member
UID 74192
Gender Male
From China
Status Offline
First, thank you, brother. But the painful thing is that what I got after merging according to the methods of various experts above actually has ";"
Floor 19 Posted 2007-02-04 08:51 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 180
Posts 68
Joined 2006-12-21 23:44
19-year member
UID 74192
Gender Male
From China
Status Offline
Oh,
I made a mistake,
Brother jmz573515,
I had a little misunderstanding of your meaning just now
Now I have achieved the desired effect according to your method
Thank you again
Floor 20 Posted 2007-02-04 17:33 ·  美国 缅因州
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
sed "s/ ;/\n/g" 合并成一行的.txt> 输出结果单行的.txt

sed "s/ ;/\n/g" merged_into_one_line.txt> output_single_line.txt
Floor 21 Posted 2007-02-04 18:02 ·  中国 甘肃 兰州 城关区 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by amao at 2007-2-4 17:33:
sed "s/ ;/\n/g" 合并成一行的.txt> 输出结果单行的.txt
Can't see how it is implemented
Floor 22 Posted 2007-02-04 21:58 ·  美国 缅因州
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
Originally posted by vkill at 2007-2-4 18:02:

Can't see how it's implemented



You can execute the one I merged earlier and this split one to find out.
Floor 23 Posted 2007-02-05 00:59 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 180
Posts 68
Joined 2006-12-21 23:44
19-year member
UID 74192
Gender Male
From China
Status Offline
Originally posted by amao at 2007-2-4 04:33 AM:
sed "s/ ;/\n/g" 合并成一行的.txt> 输出结果单行的.txt


Brother amao, why does my cmd say that "sed" is not an internal or external command??
I can't see the expected result for the time being

May I ask, Brother amao, what kind of file is the statement saved as to be executed??
Floor 24 Posted 2007-02-05 02:24 ·  美国 缅因州
中级用户
★★
Credits 316
Posts 152
Joined 2006-06-18 13:01
20-year member
UID 57204
Gender Male
Status Offline
RE dy2003310

sed is not an internal command of XP

Please search related posts with the keyword sed

Save the statement as a .bat batch file to execute. Of course, change "merged into one line.txt, output result single line.txt" and so on to corresponding names
Floor 25 Posted 2007-02-05 03:41 ·  中国 湖北 武汉 电信
新手上路
Credits 16
Posts 7
Joined 2007-02-02 06:14
19-year member
UID 78397
Gender Male
Status Offline
Originally posted by 3742668 at 2006-7-19 09:39 AM:
In practical applications of batch processing, it is recommended not to use too many variables.

for /f "delims=" %i in (source file.txt) do @set /p "var=%i;" <nul >>target file.txt

Using set /p "variable=display content" <nul to replace echo display content, the output does not automatically wrap lines. Wonderful, I didn't expect set can be used like this :D

[ Last edited by lbqldos on 2007-2-4 at 02:43 PM ]
Floor 26 Posted 2007-02-07 07:12 ·  中国 广东 广州 荔湾区 电信
初级用户
★★
Credits 180
Posts 68
Joined 2006-12-21 23:44
19-year member
UID 74192
Gender Male
From China
Status Offline
Thanks, Brother amao
I'm studying
Forum Jump: