![]() |
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-29 08:05 |
47,816 topics / 349,916 posts / today 0 new / 48,265 members |
| DOS批处理 & 脚本技术(批处理室) » How to extract only the specified content from a text file |
| Printable Version 2,946 / 7 |
| Floor1 lanlinlan | Posted 2007-01-06 22:36 |
| 初级用户 Posts 29 Credits 76 | |
|
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 ] |
|
| Floor2 9527 | Posted 2007-01-06 22:56 |
| 银牌会员 Posts 438 Credits 1,185 From 北京 | |
|
```
for /f "tokens=3,5 delims== " %a in (sfhr.txt) do @echo %~a %~b ``` |
|
| Floor3 lanlinlan | Posted 2007-01-06 23:52 |
| 初级用户 Posts 29 Credits 76 | |
|
It seems not work oh!!! The test fails
|
|
| Floor4 redtek | Posted 2007-01-07 00:37 |
| 金牌会员 Posts 1,147 Credits 2,902 | |
|
I can be tested ~ :)
Run the test by directly entering the command in the CMD Shell: 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 ~ :) |
|
| Floor5 vkill | Posted 2007-01-07 02:26 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
sed "s/.*\([0-9]\{15\}\).*\([^0-9=\x22]\{16\}\).*/\1 \2/" SFHR.txt
|
|
| Floor6 lanlinlan | Posted 2007-01-07 09:39 |
| 初级用户 Posts 29 Credits 76 | |
|
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? |
|
| Floor7 namejm | Posted 2007-01-07 09:42 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Replace %%b with %%~b.
|
|
| Floor8 lanlinlan | Posted 2007-01-07 09:54 |
| 初级用户 Posts 29 Credits 76 | |
|
Hehe, really thank you all, it's done!!!
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |