![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-11-10 12:14 |
47,815 topics / 349,930 posts / today 0 new / 48,291 members |
| DOS批处理 & 脚本技术(批处理室) » Question: Organize the text (newcomers and veterans are all welcome to try) |
| Printable Version 7,676 / 54 |
| Floor16 slore | Posted 2008-07-13 22:10 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
Originally posted by 26933062 at 2008-7-13 21:59: Oh, then I also said that for the bat, it's up to you to show... For the VBS, there are only two sentences, and I've already mentioned it... If you want to use VBS, you just need to complete the reading and writing yourself... |
|
| Floor17 lpk130 | Posted 2008-07-13 22:11 |
| 初级用户 Posts 30 Credits 80 | |
|
```
@echo off&setlocal enabledelayedexpansion for /f "tokens=*" %%a in (a.txt) do ( set "string=%%a"&set "str=%%a" if "!str:~0,1!"=="。" echo 。&echo. call :loop if "!str:~-1!"=="。" echo 。&echo. ) :loop for /f "tokens=1,* delims=。" %%i in ("!string!") do ( set string=%%j if defined string ( set/p=%%i。<nul echo.&echo. goto loop ) else ( set/p=%%i<nul ) ) ``` The code is a bit complicated |
|
| Floor18 26933062 | Posted 2008-07-13 22:16 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
The idea on the 14th floor is far - fetched? You're so amazing. Admire you. Completely don't understand. Still take a look at the pure batch file.
|
|
| Floor19 26933062 | Posted 2008-07-13 22:23 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
The person on the 17th floor should have got full marks. It's a pity I can't rate today, I'll make it up tomorrow.
My code. The idea is similar to the 17th floor. |
|
| Floor20 HAT | Posted 2008-07-13 22:24 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Although I can't understand the code on floor 14, I think it doesn't meet the LZ's requirements. From the last few lines, it should be that all 0D0A (carriage return line feed) are replaced with empty, that is, the entire text content is merged into one line, and then the periods are replaced with carriage return line feeds. This goes against the original intention of the LZ. However, the code itself is still worthy of our study. I wonder if brother qzwqzw can explain it?
|
|
| Floor21 qzwqzw | Posted 2008-07-13 23:33 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Actually, according to the original poster's intention, originally using text replacement tools like change, sed, etc. was efficient and highly compatible. But for some reason, the original poster must have a pure P solution. So I had to compromise a bit. Use ASCII Assembler to generate a text replacement tool, and then use it to replace the source text. As for whether it is purely P, there is no need to discuss it too much.
------------------------------------------------------------------ For details about ASCII Assembler, search the past posts (by content). The following is the usage instructions and source code of sbs2: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Usage: sbs2.com NUMBER "STRING1" "STRING2" <infile >outfile :: :: infile and outfile must be files (to allow random access), so in :: NT/W2000/XP no pipe (program1 | sbst | program2) must be used! :: infile and outfile must not be the same file! :: :: Substitutes the NUMBER ocurrence of STRING1 in infile by :: STRING2 and writes the result to outfile :: :: You can include any character in STRING1/2 by using its :: hex value (e.g. $0d for <CR> or $1a for EOF) :: :: If NUMBER = 0 all STRING1 are substituted by STRING2 :: :: If an error is detected or nothing is substituted, erorrlevel=0 :: replace the original file only if errorlevel>=1 (=number of :: substitutions). :: :: Instead of the double quotes (") you can also use single quotes (') :: with a different meaning for string2: :: "string2" : normal substitution :: 'string2" : before substitution the output file is rewinded :: "string2' : after substitution the outputfile is closed some examples: ----------------------------------------------------- Substitutes the 2. occurrence of user by Susan ----------------------------------------------------- sbs2.com 2 "user" "Susan" <%1 >_._ if errorlevel 1 copy _._ %1 del _._ ----------------------------------------------------- Converts dos textfiles to unix textfiles ----------------------------------------------------- sbs2.com 0 "$0d" "" <%1 >_._ if errorlevel 1 copy _._ %1 del _._ ----------------------------------------------------- Converts unix textfiles to dos textfiles ----------------------------------------------------- sbs2.com 0 "$0a" "$0d$0a" <%1 >_._ if errorlevel 1 copy _._ %1 del _._ ----------------------------------------------------- echo without CRLF ----------------------------------------------------- echo set a=|sbs2.com 0 "$0d$0a" "" >_.bat ----------------------------------------------------- Remove trailing blanks from all lines ----------------------------------------------------- :start sbs2.com 0 " $0d" "$0d" <%1 >_._ if not errorlevel 1 goto ende copy _._ %1 goto start :ende del _._ ----------------------------------------------------- Remove all single CR LF (ascii text file -> WORD) ----------------------------------------------------- sbs2.com 0 "$0d$0a$0d$0a" "$0a" <%1 >_._ if errorlevel 1 copy _._ %1 sbs2.com 0 "$0d$0a" "" <%1 >_._ if errorlevel 1 copy _._ %1 sbs2.com 0 "$0a" "$0d$0a" <%1 >_._ if errorlevel 1 copy _._ %1 del _._ ----------------------------------------------------- Extract line 5-9 from a text file ----------------------------------------------------- sbs2.com 4 "$0d$0a" '" <%1 >_._ if errorlevel 1 copy _._ %1 sbs2.com 5 "$0d$0a" "$0d$0a' <%1 >_._ if errorlevel 1 copy _._ %1 ----------------------------------------------------- The source code ----------------------------------------------------- @=$100 move.w #$81,r5 movu.bw -1.b(r5.w),r2 eor.l r0,r0 eor.l r4,r4 .lab1: _10: dec.w r2 bmi.w x100 move.b (r5.w),r0 inc.w r5 cmp.b #'0',r0 blo.b _20 cmp.b #'9',r0 bhi.b _20 sub.b #'0',r0 mulsq.l #10,r4,r4 add.l r0,r4 move.w #_30,lab1 br.b _10 _20: jmp.w (lab1) _30: move.l r4,number move.w #buf1,r6 bsr.w get_string or.w r6,r6 beq.b .x100 move.w #buf2,r6 bsr.w get_string eor.l r5,r5 _a00: move.w #buf1,r6 eor.w r4,r4 _a10: move.b #$3f,m0 move.w #buf0,r1 move.w #1,r2 eor.w r3,r3 trap #$21 bcs.b .x100 or.w r0,r0 beq.b _x100 move.b buf0,r0 cmp.b (r6.w),r0 beq.b _a20 _a50: or.w r4,r4 beq.b _a30 move.w #$4201,r0 move.w #-1,r2 move.w r4,r1 neg.w r1 trap #$21 move.w #buf1,r1 move.w #1,r2 _a30: move.b #$40,m0 inc.w r3 trap #$21 bcs.b .x100 cmp.w #buf2,r1 bne.b _a60 tst.b #1,stop bne.b _x110 _a60: cmp.w r0,r2 beq.b _a00 .x100: br.b x100 _a20: inc.w r6 inc.w r4 cmp.w buf1l,r4 blo.b _a10 inc.l r5 move.l number,r0 or.l r0,r0 beq.b _a40 cmp.l r0,r5 beq.b _a40 dec.w r4 move.w #buf1,r1 move.w #1,r2 br.b _a50 _a40: tst.b #1,start beq.b _a41 move.w #$4200,r0 eor.w r1,r1 eor.w r2,r2 inc.w r3 trap #$21 move.b #$40,m0 trap #$21 dec.w r3 _a41: move.w #buf2,r1 move.w buf2l,r2 br.b _a30 _x100: or.w r4,r4 beq.b _x110 move.w #buf1,r1 move.w r4,r2 br.b _a30 _x110: move.w r5,r0 or.l r5,r5 beq.b x101 move.l number,r1 or.l r1,r1 beq.b _x120 cmp.l r5,r1 bhi.b x100 move.b #1,r0 br.b x101 _x120: cmp.l #$ff,r5 bls.b x101 move.b #-1,r0 br.b x101 x100: eor.b r0,r0 x101: move.b #$4c,m0 trap #$21 get_string: eor.w r1,r1 move.w r6,r3 move.w #_10,lab1 move.w #_30,lab2 ; move.l #(_30<<16)+_10,lab1 ; kuerzer _10: dec.w r2 bmi.b _x100 move.b (r5.w),r0 inc.w r5 eor.b m0,m0 cmp.b #'"',r0 beq.b _20 cmp.b #"'",r0 beq.b _21 jmp.w (lab1) _21: inc.b m0 _20: jmp.w (lab2) _30: move.w #_40,lab1 move.w #_50,lab2 ; move.l #(_50<<16)+_40,lab1 ; kuerzer move.b m0,start br.b _10 _40: or.b r1,r1 bne.b _41 cmp.b #'$',r0 bne.b _42 move.w #2,r1 br.b _10 _42: move.b r0,(r6.w) inc.w r6 br.b _10 _41: or.b #$20,r0 sub.b #'a'-10,r0 bpl.b _43 add.b #'a'-10-'0',r0 _43: lsl.b #4,m1 add.b m1,r0 dec.b r1 beq.b _42 move.b r0,m1 br.b _10 _50: sub.w r3,r6 move.w r6,-2.b(r3.w) move.b m0,stop rts.w _x100: addq.w #2,r7 br.b x100 lab1: dc.w .lab1 lab2: blk.w 1 even start: blk.b 1 stop: blk.b 1 number: blk.l 1 buf0: blk.w 1 buf1l: blk.w 1 buf1: blk.w 200 buf2l: blk.w 1 buf2: blk.w 200 |
|
| Floor22 bat-zw | Posted 2008-07-14 00:27 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Feels like the thinking and efficiency are still okay, so I posted it:
[ Last edited by zw19750516 on 2008-7-14 at 12:28 AM ] |
|
| Floor23 hackerscans | Posted 2008-07-14 09:20 |
| 初级用户 Posts 51 Credits 73 | |
|
Xiaocai is learning here. Also congratulations to ZW19750516 for being promoted to Gold Member.
|
|
| Floor24 HAT | Posted 2008-07-14 09:31 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Brother qzwqzw, can you write one in sed version? I want to learn.
What I wrote doesn't work. The part after the pipe doesn't seem to take effect. |
|
| Floor25 lxmxn | Posted 2008-07-14 15:03 |
| 版主 Posts 4,938 Credits 11,386 | |
| Floor26 26933062 | Posted 2008-07-14 15:28 |
| 银牌会员 Posts 879 Credits 2,268 | |
Originally posted by lxmxn at 2008-7-14 15:03: I've racked my brains and still can't figure it out. Can the moderator explain this command? In "/。$\|^$/", is the pipe here meaning "or"? Then the preceding \ is an escape character? Your code will display an extra blank line when the line starts with a period. I modified it as follows. I wonder if it will go wrong in some cases? Also: Can it be solved without using the pipe symbol? [ Last edited by 26933062 on 2008-7-14 at 03:29 PM ] |
|
| Floor27 HAT | Posted 2008-07-14 15:43 |
| 版主 Posts 5,017 Credits 9,023 | |
|
The moderator is very smart, I've learned.
But I found that this will add an extra blank line after the line that originally ends with a period. The modification is as follows: |
|
| Floor28 HAT | Posted 2008-07-14 15:47 |
| 版主 Posts 5,017 Credits 9,023 | |
|
\ is an escape character, | is not a pipe, but "or"
/.\$\|\^$/! means to execute the following command on non - empty lines that do not end with a period |
|
| Floor29 qzwqzw | Posted 2008-07-14 15:53 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
I'm sorry, correct a sentence.
The most concise, efficient and general solution to realize the building owner's intention is to use full-text text replacement tools such as change, hexc, etc. Rather than text editing tools in line-buffered form such as sed/awk, Because the grammar of the latter will be too obscure when dealing with cross-line problems, And the compatibility is not very high, Because there are great differences in the support of many non-standard marks among multiple implementations of sed and awk. I know very little about sed. Basically, I only know the part of regular expressions. I haven't been exposed to others. But I have doubts about the compatibility of marks like :nt, {N;b nt}, etc. [ Last edited by qzwqzw on 2008-7-14 at 03:55 PM ] |
|
| Floor30 lxmxn | Posted 2008-07-14 15:53 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Well, it just means "or". Actually, I'm not proficient in sed either, I just made it up randomly...
|
|
| Prev 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |