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-22 00:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question: Organize the text (newcomers and veterans are all welcome to try) View 6,077 Replies 54
Original Poster Posted 2008-07-13 19:51 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
### Requirements: Organize a.txt by breaking lines at periods, that is, concatenate lines without periods with the next line, and break lines with periods at the period. Note: There may be several consecutive lines without periods, or multiple periods in one line. No need to consider special character issues. Of course, the premise is that you cannot concatenate all the content of a.txt into one variable. (Because the character limit of the variable is limited) See who has the most concise and efficient code, plus points..!
### Content of a.txt:
```
Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS. It has flexible operability and can adapt to various complex computer operations. The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order.
That is to summarize the commands executed one by one, execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands. At the same time, batch processing files also have some programming characteristics. It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work. Batch processing. bat. cmd. Each has its own limitations. Each has its own advantages.
```
### Required output format:
```
Batch processing files (Batch File, referred to as BAT files) are a most commonly used executable file under DOS.

It has flexible operability and can adapt to various complex computer operations.

The so-called batch processing means automatically executing several specified DOS commands or programs in a prescribed order.

That is to summarize the commands executed one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.

At the same time, batch processing files also have some programming characteristics.

It can flexibly control the execution of the program through extended parameters, so it is very practical in daily work.

Batch processing.

bat.

cmd.

Each has its own limitations.

Each has its own advantages.
```
### Summary:
There are many answers, (2nd floor 14th floor 17th floor 19th floor)
The 2nd floor adopts the method of reading character by character, and can handle most special characters, but the efficiency is too low.
The 14th floor created a com file, which is extremely efficient. Unfortunately, I don't understand it, but I have gained knowledge. However, this question is still solved with pure p.
The ideas of the 17th floor and the 19th floor are the same, the code is slightly different, and the efficiency is also good, basically meeting the requirements of the building owner.

[ Last edited by 26933062 on 2008-7-13 at 10:55 PM ]
致精致简!
Floor 2 Posted 2008-07-13 20:18 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Read character by character

@echo off
for /f "delims=" %%i in ('findstr /n .* 1.txt') do (
set "str=%%i"
setlocal enabledelayedexpansion
set str=!str:*:=!
call :lp
endlocal
)
pause&exit
:lp
if defined str (
set /p= !str:~0,1!<nul
if "!str:~0,1!"=="。" echo.
set str=!str:~1!
goto lp
)

Ignore special characters, can also be simplified

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (1.txt) do set str=%%i&call :lp
pause&exit
:lp
set /p= !str:~0,1!<nul
if "!str:~,1!"=="。" echo.
set str=!str:~1!
if defined str goto lp


[ Last edited by terse on 2008-7-13 at 08:23 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
26933062 +5 2008-07-13 20:22
简单!简单!再简单!
Floor 3 Posted 2008-07-13 20:21 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Reading character by character is indeed an option, but the efficiency will be greatly reduced. Add 5 points.
致精致简!
Floor 4 Posted 2008-07-13 20:29 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Can I replace "." with "echo."?
简单!简单!再简单!
Floor 5 Posted 2008-07-13 20:37 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.

That is to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.

How is the punctuation of this determined?
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 6 Posted 2008-07-13 20:58 ·  中国 江苏 苏州 电信
高级用户
★★
五星老土
Credits 558
Posts 172
Joined 2003-02-09 00:00
23-year member
UID 881
Gender Male
From 江苏
Status Offline
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%i in (text.txt) do (
set str=%%i
set/p=!str!<nul>>temp.txt)
for /f "delims=。" %%i in (temp.txt) do (echo %%i。&echo.)>>result.txt

It's a pity that things didn't go as expected. The final result is only one line. Experts, please help modify it. I think the idea is correct.
我怎么找不到一个比我注册日期早的人? 难道我是传说中的超级管理员? 其实我只是个潜水冠军而已.
Floor 7 Posted 2008-07-13 21:22 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Has Brother Laotu ever studied the maximum number of characters that can fit in one line of a text file? If it exceeds this limit, is your idea still correct?
Floor 8 Posted 2008-07-13 21:44 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Back to the 5th floor
That is, to summarize the originally executed commands one by one and execute them in batches, and the program file can be ported to other computers for operation, so it can greatly save the tediousness of repeatedly entering commands.
There is no period in the middle, so of course it counts as one sentence.
致精致简!
Floor 9 Posted 2008-07-13 21:52 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Is this okay...

@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do set str=!str!%%a
set str=%str:。=。^&echo.^&echo.%
echo %str%
pause>nul

I'm sorry, I forgot to read the question in detail...

[ Last edited by pusofalse on 2008-7-13 at 09:56 PM ]
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 10 Posted 2008-07-13 21:54 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Is that a typesetting issue? I just don't understand why the Chinese characters are broken...

If it's VBS: replace "carriage return" with "empty", replace "。" with "。+carriage return"
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 11 Posted 2008-07-13 21:54 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The LZ doesn't allow this, heh heh.
Floor 12 Posted 2008-07-13 21:55 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Under Unix this should work, but under Windows it just doesn't. Thinking...
sed "s/。/。\n/g" a.txt | sed "/。$/!s/\n//g"
Floor 13 Posted 2008-07-13 21:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Originally posted by slore at 2008-7-13 21:54:
That's a typesetting issue? I just don't understand why it breaks at the Chinese character...

If it's VBS: replace "carriage return" with "empty", replace "。" with "。+carriage return"

It's not breaking at the "中" character, it's the forum automatically wrapping it.
So in my sample, empty lines represent line breaks. Is that clear?
致精致简!
Floor 14 Posted 2008-07-13 22:01 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Change the idea


@echo off
chcp 437 >nul & graftabl 936 >nul
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>sbs2.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>sbs2.com
echo ?@}IKuNWpe~Fpe?FNHlF?wGMECIQqo{Ox{T?kPv@jeoSeIlRFD@{AyEKj@>>sbs2.com
echo iqe~1NeAyR?mHAG~BGRgB{~H?o~TsdgCYqe?HR~upkpBG?~slJBCyA?@xA>>sbs2.com
echo LZp{xq`Cs?H











Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
26933062 +15 2008-07-13 22:15
Floor 15 Posted 2008-07-13 22:01 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
I think it might be a bug in Notepad. Sometimes it works fine, but when you close it and open it again, the Notepad will have a break in the middle.
┌───────┐
├→学习→实践→┤
└───────┘
Forum Jump: