Board logo

标题: 如何提取超长行指定字符串 [打印本页]

作者: suntb     时间: 2009-1-5 15:59    标题: 如何提取超长行指定字符串
有一文本(飞信手机型号列表)存在超长行,我想提取其中指定的字符串,用P能实现吗?
文本部分示例如下,具体可看附件
批处理一:提取每一对括号内的前两个引号中的内容
1680C 1
310 3
2610 1
以此类推
批处理二:以每一对括号内的第二个引号中的内容为分类标志,提取相应的括号内的第一个引号中的内容
如示例中要提取分类标志为1的所有相应数值,则有
1680C
2610
等等,以此类推

mobiletype = new Array("1680C","1","309");mobiletype = new Array("310","3","14");mobiletype = new Array("2610","1","103");......



或者问题简单化,能不能通过P处理的方式将此超长文本行以分号为分隔符变成如下短行
mobiletype = new Array("1680C","1","309")
mobiletype = new Array("2610","1","103")
mobiletype = new Array("2630","1","200")
mobiletype = new Array("2760","1","201")
mobiletype = new Array("310","3","14")



Last edited by suntb on 2009-1-5 at 16:48 ]
附件 1: test.rar (2009-1-5 15:59, 2.94 KiB,下载次数: 13)

作者: suntb     时间: 2009-1-5 16:01
如果不用P的话怎么办?我还是喜欢使用P处理,不过P用来处理类似的超长行实在头痛啊

作者: linee     时间: 2009-1-5 16:39
先把超长行变短是不是好处理点呢?
mobiletype = new Array("1680C","1","309")
mobiletype = new Array("2610","1","103")
mobiletype = new Array("2630","1","200")
mobiletype = new Array("2760","1","201")
mobiletype = new Array("310","3","14")
mobiletype = new Array("3109c","1","296")
mobiletype = new Array("3110C","1","153")
mobiletype = new Array("3220","1","102")
mobiletype = new Array("3230","1","2")
mobiletype = new Array("3250","1","168")
……

作者: suntb     时间: 2009-1-5 16:45
Originally posted by linee at 2009-1-5 16:39:
先把超长行变短是不是好处理点呢?

如果能将超长行变短,其他的问题我自己可以解决了
问题是怎么通过P方式变短?

作者: linee     时间: 2009-1-5 19:56
超长行纯P可能读不出来,可能要借助第三方工具。

刚测试了下,P最长能处理8184个字符,用P处理的话,你这文本至少要分4次处理。

Last edited by linee on 2009-1-5 at 21:00 ]

作者: tireless     时间: 2009-1-6 00:14
执行 set /p str=<test.txt,得到的 str 的值为 1023 个字符。

Last edited by tireless on 2009-1-6 at 00:19 ]

作者: linee     时间: 2009-1-6 12:06
Originally posted by tireless at 2009-1-6 00:14:
执行 set /p str=<test.txt,得到的 str 的值为 1023 个字符。

Last edited by tireless on 2009-1-6 at 00:19 ]

用for能取到8184个字符。

作者: slore     时间: 2009-1-6 12:21    标题: 要不用P调用下面的VBS替换;为回车
Dim objFSO,objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("test.txt")
strall = objFile.ReadAll
objFile.Close

strall = Replace(strall,";",vbCrLf)

作者: netbenton     时间: 2009-1-17 03:18    标题: 用debug实现了
@echo on&setlocal enabledelayedexpansion
goto :skip
f 90 l17 50 51 56 57 BF 00 01 89 FE AC 3C 3B 75 02 B0 0A AA E2 F6 5F 5E 59 58
f a7 l4 90
t=90
g a8
w
q

:skip
copy test.txt aaa /y
debug aaa <%~nx0
rem 上面,以 ; 号为分隔符将数据分行

cd.>rus.txt
for /f "tokens=1-3,*" %%a in (aaa) do (
set aa=%%d
set aa=!aa:"=`!
for /f "tokens=1-4 delims=`," %%i in ("!aa!") do (

rem ****aaa
set jj=%%j
set jj=!jj: =`!
rem ****aaa 此段用来处理字符串内的空格

set "_%%k=!_%%k! !jj!"
)
)
rem 以上,读取数据并分类存入变量


for /f "tokens=1,*" %%a in ('set _') do (
set aa=%%a
set aa=!aa:~1,-1!
echo ***** !aa! 类 *****>>rus.txt
for %%i in (%%b) do (set ii=%%i&set ii=!ii:`= !&echo !ii! >>rus.txt)
echo **** end !aa! ****>>rus.txt
echo.>>rus.txt
)
rem 将分类好的变量整理,写入文本文件

pause

Last edited by netbenton on 2009-1-17 at 03:22 ]

作者: knoppix7     时间: 2009-1-17 21:19
Debug的话..
碰到大于64K的文档就....

建议学下gawk..

作者: netbenton     时间: 2009-1-18 00:11
谢谢,gawk是很值得学习
但debug应该不算第三方工具吧
debug 在500k以内还是可以处理的,只是汇编代码还要增加

Last edited by netbenton on 2009-1-18 at 00:14 ]