![]() |
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-11 09:48 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved][NT] How to search for keywords in ultra-long lines? |
| Printable Version 809 / 8 |
| Floor1 amark | Posted 2009-02-03 15:47 |
| 新手上路 Posts 3 Credits 3 | |
|
What I need to do is like this:
There is an XML message, about 1 MB in size, and the longest line is a little over 4000 bytes. In that case, the find command can't search for keywords in such ultra-long lines. Current ideas: 1, use the findstr command; I've tested it, and it can search 4 KB lines 2, split the long lines into short lines; this is basically a matter of parsing the message. I hope friends with similar experience can discuss it together. [ Last edited by amark on 2009-2-9 at 11:20 ] |
|
| Floor2 yishanju | Posted 2009-02-03 15:54 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
. Paste a sample here so we can have a look
|
|
| Floor3 yishanju | Posted 2009-02-03 16:03 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
xmlstarlet
F http://baiy.cn/utils/f/index.htm SED AWK and so on, tools like these should be up to the job |
|
| Floor4 HAT | Posted 2009-02-03 20:37 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Since the findstr command can search 4 KB lines, why not use it?
|
|
| Floor5 amark | Posted 2009-02-04 09:08 |
| 新手上路 Posts 3 Credits 3 | |
|
Uh, here's the situation.
After findstr searches and returns that 4 KB line, I still need to find specific key fields within those 4 KB. For example: <errorfields><field name="date" type="0" value="" value1=今天" value2="昨天" time1="20090204" time2="20090203"/></errorfields> and extract several values from this section, such as "今天" "昨天" "20090204" "20090203". Yesterday I tried using for /f "tokens=31* delims=<> usebackq" %%i in (error.txt) to do this step. As a result, %%i could only get the content of the 31st node, such as attribute name="television" type="0" value="1" But when I wanted to further process %%j, that is, the string containing the required key fields, since the xml is UTF-8 encoded, echo %%j would produce a pile of garbled text. I'm sorting out my thinking right now. PS: due to limitations, I can't use third-party tools. Thanks in advance for the suggestion in reply #2 [ Last edited by amark on 2009-2-4 at 09:11 ] |
|
| Floor6 netbenton | Posted 2009-02-04 09:31 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
Then convert it to ASCII and use third-party processing,
I think for /f may not be able to handle long fields over 4k, and with many nodes it definitely can't handle it. Unless you use some other way to split the lines again. |
|
| Floor7 yishanju | Posted 2009-02-04 15:40 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
At most the code would be a bit more complicated; batch processing should be able to cut out the required strings from XML.
Upload a file and we'll know at a glance |
|
| Floor8 amark | Posted 2009-02-09 11:25 |
| 新手上路 Posts 3 Credits 3 | |
|
I finished it last week. I called one vbs to replace > with >/n, which solved the long-line problem. I called another vbs to convert utf8 to unicode, then type it to ansi. That solved the garbled text problem. Thanks here to all the posters above for their opinions and suggestions.
|
|
| Floor9 yishanju | Posted 2009-02-09 12:19 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
Post the code too, let everyone share it
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |