![]() |
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-08-08 17:15 |
47,811 topics / 349,895 posts / today 0 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] How to align text with bat? |
| Printable Version 5,732 / 30 |
| Floor1 wydos | Posted 2006-12-13 07:15 |
| 中级用户 Posts 117 Credits 304 | |
|
New Compilation of Essentials for TCM Clinical Practice
Author: Lu Xiangzhi SS Number: 10804820 Call Number: R24/15 Basic Theory of TCM Clinical Medicine Author: Hunan College of TCM SS Number: 10806223 Call Number: R24/1 Essential Discussions on Clinical Syndrome Treatment Author: Xu Chunjia, Qin Qun SS Number: 10806254 Call Number: R24/152 [ Last edited by wydos on 2006-12-13 at 07:17 AM ] |
|
| Floor2 a9319751 | Posted 2006-12-13 07:19 |
| 中级用户 Posts 170 Credits 439 | |
|
Vaguely remember that there is one that can make TAB tab. It seems to be 8 spaces.
|
|
| Floor3 namejm | Posted 2006-12-13 07:35 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
We need to count the maximum length of each section of the string to facilitate typesetting.
|
|
| Floor4 lxmxn | Posted 2006-12-13 07:53 |
| 版主 Posts 4,938 Credits 11,386 | |
|
I don't know if WMIC can do it. Just ask the moderator and you'll know. |
|
| Floor5 youxi01 | Posted 2006-12-13 08:03 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Personally, purely using P is difficult to implement because it's hard to judge the number of bytes of variables, so we need to rely on vbs.
Description: Save the text to be processed as test.txt, and save this code as: ok.bat [ Last edited by youxi01 on 2006-12-13 at 08:14 AM ] |
|
| Floor6 electronixtar | Posted 2006-12-13 09:15 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
Sweat, WMIC is used to handle text~~~ |
|
| Floor7 pengfei | Posted 2006-12-13 12:09 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
```
@echo off setlocal enabledelayedexpansion for /f "tokens=1-4 delims=Author: SS number: Call number: " %%i in (test.txt) do ( set a=&set b=&set c= call :detect %%i set /a num=2*10-2*num call :add %%i set a=!i! call :detect %%j set /a num=2*8-2*num call :spa %%j set /a num+=!sp! call :add %%j set b=!i! call :detect %%k set /a num=12-num call :add %%k set c=!i! echo !a!Author: !b!SS number: !c!Call number: %%l>>array.txt ) start array.txt goto :eof :detect set x=%*◎ set num=0 :detect_ if not "%x:~0,1%"=="◎" ( set /a num+=1 set "x=%x:~1%" goto :detect_ ) goto :eof :add set y=%* for /l %%i in (1,1,%num%) do set y=!y! set i=%y% goto :eof :spa set z=%*◎ set sp=0 :spa_ if not "%z:~0,1%"=="◎" ( if "%z:~0,1%"==" " set /a sp+=1 set "z=%z:~1%" goto :spa_ ) goto :eof ``` Only tested the three lines you provided, and other formats and special characters were not considered. Please note the difference between full-width and half-width colons. [ Last edited by pengfei on 2006-12-13 at 12:53 PM ] |
|
| Floor8 zh159 | Posted 2006-12-13 14:30 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
“delims=Author: SS number: Call number:” has a shortcoming. As long as there is one of these characters in a certain position, it will cause a loss.
You can first consider replacing "Author:", "SS number:", "Call number:" with $ and then handle it. Highlight: Detect byte count >Temp.txt set/p=!Temp_%1!<nul [ Last edited by zh159 on 2006-12-13 at 09:35 AM ] |
|
| Floor9 HUNRYBECKY | Posted 2006-12-13 21:53 |
| 银牌会员 Posts 442 Credits 1,179 | |
|
It's all great. I've always been not good at using the FOR statement. I didn't expect the FOR statement to be so useful. Learned it.
|
|
| Floor10 HUNRYBECKY | Posted 2006-12-13 22:14 |
| 银牌会员 Posts 442 Credits 1,179 | |
Originally posted by youxi01 at 2006-12-13 08:03: |
|
| Floor11 youxi01 | Posted 2006-12-14 01:18 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Because :: can be recognized (identified as a line break) in VBS, while rem cannot be recognized by VBS!
|
|
| Floor12 youxi01 | Posted 2006-12-14 01:22 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Question from user 7F: If there are E characters or numbers in the book title, how to solve it?
What an excellent idea by user 8F to judge the number of bytes by the size of the file! |
|
| Floor13 qzwqzw | Posted 2006-12-14 01:51 |
| 银牌会员 Posts 636 Credits 2,343 | |
|
Aligning or first supplementing and then splitting is the most convenient.
|
|
| Floor14 无奈何 | Posted 2006-12-14 02:31 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
Brother zh159, the use of byte count to determine length in building 8 is indeed a highlight. In CMD, both Chinese characters and English letters in a string have a length of 1, and using byte judgment well solves this problem. However, special characters in CMD are really a headache, and I have not found a good method all the time.
This post is a very typical problem of formatted output. Most languages' printf can solve it well. You can try the following awk script: Usage: gawk -f script.awk file.txt gawk download: http://www.klabaster.com/progs/gawk32.zip [ Last edited by 无奈何 on 2006-12-14 at 03:23 AM ] |
|
| Floor15 ccwan | Posted 2006-12-14 02:44 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
I'm sorry I'm slow-witted, I can't understand brother's code.
To avoid the suspicion of flattery, I won't give brother points, please understand. |
|
| 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |