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-07-15 00:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to extract only the specified content from a text file View 2,852 Replies 7
Original Poster Posted 2007-01-06 22:36 ·  中国 浙江 杭州 华数宽带
初级用户
Credits 76
Posts 29
Joined 2006-11-18 23:59
19-year member
UID 70996
Gender Male
Status Offline
The following file, I only want the taxpayer identification number and the taxpayer name, and nothing else. How to achieve it?

The system is WINXP SP2, the file is a text file SFHR.txt, and the style is as follows:
<RECORD 纳税人识别号="111111111111111" 纳税人名称="测试测试测试测试" 状态="0" 地址="" 邮编="" 联系人="" 联系电话="" />
<RECORD 纳税人识别号="111111111111112" 纳税人名称="杭州技术有限公司" 状态="0" 地址="" 邮编="" 联系人="" 联系电话="" />

Now I just want to keep:

111111111111111 测试测试测试测试
111111111111112 杭州技术有限公司

[ Last edited by namejm on 2007-1-6 at 08:57 PM ]
Floor 2 Posted 2007-01-06 22:56 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
19-year member
UID 61449
From 北京
Status Offline
```
for /f "tokens=3,5 delims== " %a in (sfhr.txt) do @echo %~a %~b
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2007-01-07 00:40
我今后在论坛的目标就是做个超级坏人!!!
Floor 3 Posted 2007-01-06 23:52 ·  中国 浙江 杭州 华数宽带
初级用户
Credits 76
Posts 29
Joined 2006-11-18 23:59
19-year member
UID 70996
Gender Male
Status Offline
It seems not work oh!!! The test fails
Floor 4 Posted 2007-01-07 00:37 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
I can be tested ~ :)

Run the test by directly entering the command in the CMD Shell:



C:\TEMP\str>for /f "tokens=3,5 delims== " %a in (sfhr.txt) do @echo %~a %~b
111111111111111 Test Test Test Test
111111111111112 Hangzhou Technology Co., Ltd.



Brother 9527 used a single % sign in the for command (which means it's run directly on the command line and can't be run in a .bat file). So Brother lanlinlan can run it directly.

If you want to write it in a batch file, use double % signs ~ :)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2007-01-07 02:26 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
sed "s/.*\([0-9]\{15\}\).*\([^0-9=\x22]\{16\}\).*/\1 \2/" SFHR.txt
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2007-01-07 02:31
Floor 6 Posted 2007-01-07 09:39 ·  中国 香港 腾讯云
初级用户
Credits 76
Posts 29
Joined 2006-11-18 23:59
19-year member
UID 70996
Gender Male
Status Offline
Hehe, impressive. It's okay to do it directly in CMD. Just that I want to output to a.txt.

for /f "tokens=3,5 delims== " %%a in (sfhr.txt) do @echo %%~a %%b >>a.txt

Why does the output look like:

111111111111111 "Test Test Test Test"
111111111111112 "Hangzhou Technology Co., Ltd."

How to write it to remove the quotes?
Floor 7 Posted 2007-01-07 09:42 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Replace %%b with %%~b.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 8 Posted 2007-01-07 09:54 ·  中国 香港 腾讯云
初级用户
Credits 76
Posts 29
Joined 2006-11-18 23:59
19-year member
UID 70996
Gender Male
Status Offline
Hehe, really thank you all, it's done!!!
Forum Jump: