Originally posted by yoyodos at 2007-9-24 03:01 PM:
I'll post one too, haha
@echo off
setlocal enabledelayedexpansion
cd.>tmp.txt
set /a x=0
for /f "tokens=1 delims=姓名," %%r in (ab.txt) do echo %%r>>tmp.txt
fo ...
Generally speaking, there are mainly 2 key points worthy of learning
1. The usage of "tokens=1 delims=", this point is very easy to get wrong many times
2. Variable replacement and extraction
If the content of ab.txt is changed from the original:
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
........
To the following:
abcd rster_www_er Name "Zhang San", ID '102', tel '0102211', 0, 25, 11
abcd rster_www_er Name "Li Sida", ID '102', tel '0202211', 0, 25, 11
abcd rster_www_er Name "Wang Er", ID '102', tel '01023311', 0, 25, 11
....
Then the above reference answer codes all need to be appropriately modified.
From this, it can be known that if you are editing a highly universal code, it is best to use the method of fuzzy search and positioning. For example, in this case, even if the length of each line of the ab.txt file and other contents change, as long as there is a field like , it can be found and replaced.
Can this be achieved?