![]() |
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-09-25 23:05 |
47,813 topics / 349,918 posts / today 0 new / 48,275 members |
| DOS批处理 & 脚本技术(批处理室) » Replacement of conditional text files [Answered] |
| Printable Version 3,722 / 45 |
| Floor16 yoyodos | Posted 2007-09-24 13:00 |
| 初级用户 Posts 59 Credits 128 | |
|
It's very easy. Just change "echo variable" to "echo to the file".
|
|
| Floor17 123cainiao | Posted 2007-09-24 13:02 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by yoyodos at 2007-9-24 01:00 PM: Hehe, thank you. I understand. |
|
| Floor18 yoyodos | Posted 2007-09-24 13:08 |
| 初级用户 Posts 59 Credits 128 | |
|
Let's study together.. Haha
|
|
| Floor19 yoyodos | Posted 2007-09-24 15:01 |
| 初级用户 Posts 59 Credits 128 | |
|
I also post one, haha
[ Last edited by yoyodos on 2007-9-24 at 03:02 PM ] |
|
| Floor20 123cainiao | Posted 2007-09-24 15:51 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by yoyodos at 2007-9-24 03:01 PM: |
|
| Floor21 yoyodos | Posted 2007-09-24 16:10 |
| 初级用户 Posts 59 Credits 128 | |
|
I don't quite understand what you mean.
The idea is to replace "姓名" in each line of the string with "abcd rster_www_er 姓 名", right? Hahaha |
|
| Floor22 123cainiao | Posted 2007-09-24 16:40 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by yoyodos at 2007-9-24 04:10 PM: No, what I mean is that as a highly versatile search statement, using fuzzy positioning to find is more practical than using the method of finding according to the delimiter. For example, the content in the original ab.txt file: Name "Zhang San", ID '102', tel '0102211', 0, 25, 11 Name "Li Sida", ID '102', tel '0202211', 0, 25, 11 Name "Wang Er", ID '102', tel '01023311', 0, 25, 11 This is very neat. If it is not neat, it becomes: abcd rster_www_er 姓 名 "Zhang San", ID '102', tel '0102211', 0, 25, 11 abcd, er 姓 名 "Li Sida", ID '102', tel '0202211', 0, 25, 11 abcd rster, www, r 姓 名 "Wang Er", ID '102', tel '01023311', 0, 25, 11 With such a format, the design idea of strictly finding according to the delimiter is almost unusable, and only fuzzy finding can be implemented. In general, no matter how each line of text becomes, can be replaced in any different position in each line. [ Last edited by 123cainiao on 2007-9-24 at 04:43 PM ] |
|
| Floor23 yoyodos | Posted 2007-09-24 17:18 |
| 初级用户 Posts 59 Credits 128 | |
|
Oh, just use the name as the delimiter, right? Write the names after delims=, like 姓 名, 姓 名... and you can get the following names.
|
|
| Floor24 123cainiao | Posted 2007-09-24 18:49 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by yoyodos at 2007-9-24 05:18 PM: Thank you for your answer. After repeated testing and appropriate adjustments, it works. Your code has very good applicability. Thanks again! |
|
| Floor25 terse | Posted 2007-09-24 19:13 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
I also come to learn
@echo off setlocal enabledelayedexpansion set mn=0 for /f "tokens=1* delims=," %%i in (ab.txt) do ( set data=%%i%%j set /a mn+=1 for /f "tokens=1* delims=:" %%a in ('findstr /n .* cd.txt') do ( if !mn! EQU %%a set data=!data:%%i=姓名"%%b",! ) echo !data!>>c12.txt ) pause |
|
| Floor26 123cainiao | Posted 2007-09-25 13:25 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by terse at 2007-9-24 07:13 PM: Among all the previous responses, terse's one has the strongest adaptability and can be fully adapted to the search and replacement of general-purpose files without modification. Only the "name" field needs to be replaced with what you want to search for. Thank you, terse |
|
| Floor27 123cainiao | Posted 2007-09-25 13:43 |
| 初级用户 Posts 41 Credits 97 | |
|
If we extend the problem, for example, the ab.txt file has only this line:
Name "Zhang San", ID '102', tel '0102211', 0, 25, 11 Now the cd.txt file remains unchanged: Zhao Kuo Wang Bin Li Ling ...... Can we replace the name after the first line in the ab.txt file and then directly copy this format to generate a file ef.txt that has exactly the same number of lines as the cd.txt file: Name "Zhao Kuo", ID '102', tel '0102211', 0, 25, 11 Name "Wang Bin", ID '102', tel '0102211', 0, 25, 11 Name "Li Ling", ID '102', tel '0102211', 0, 25, 11 ........ Here the problem is not just about replacing corresponding lines, but also involves copying, which I think will be more complicated. |
|
| Floor28 terse | Posted 2007-09-25 14:23 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
@echo off
setlocal enabledelayedexpansion for /f "tokens=1* delims=," %%i in (ab.txt) do ( set data=%%j ) for /f "tokens=1* delims=:" %%a in (cd.txt) do ( >>c12.txt echo 姓名"%%a",!data! ) pause |
|
| Floor29 yoyodos | Posted 2007-09-25 14:29 |
| 初级用户 Posts 59 Credits 128 | |
|
Terse answer is very good, ha, does 123cainiao still have questions? I also practice
|
|
| Floor30 123cainiao | Posted 2007-09-25 16:37 |
| 初级用户 Posts 41 Credits 97 | |
Originally posted by yoyodos at 2007-9-25 02:29 PM: Hehe, thank you all for your answers. Different program expressions achieve the same goal, which is worth studying carefully. Best wishes to everyone for a happy Mid-Autumn Festival and a happy family! |
|
| Prev 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |