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-08-11 08:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Solved][NT] How to search for keywords in ultra-long lines? View 807 Replies 8
Original Poster Posted 2009-02-03 15:47 ·  美国 莱斯大学
新手上路
Credits 3
Posts 3
Joined 2009-02-03 00:08
17-year member
UID 137886
Gender Male
Status Offline
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 ]
Floor 2 Posted 2009-02-03 15:54 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
. Paste a sample here so we can have a look

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 3 Posted 2009-02-03 16:03 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
xmlstarlet
F http://baiy.cn/utils/f/index.htm

SED
AWK

and so on, tools like these should be up to the job

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 4 Posted 2009-02-03 20:37 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Since the findstr command can search 4 KB lines, why not use it?
Floor 5 Posted 2009-02-04 09:08 ·  美国 莱斯大学
新手上路
Credits 3
Posts 3
Joined 2009-02-03 00:08
17-year member
UID 137886
Gender Male
Status Offline
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 ]
Floor 6 Posted 2009-02-04 09:31 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
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.
精简
=> 个人网志
Floor 7 Posted 2009-02-04 15:40 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
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

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 8 Posted 2009-02-09 11:25 ·  美国 莱斯大学
新手上路
Credits 3
Posts 3
Joined 2009-02-03 00:08
17-year member
UID 137886
Gender Male
Status Offline
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.
Floor 9 Posted 2009-02-09 12:19 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Post the code too, let everyone share it

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Forum Jump: