嗨,
我在从文本文件中提取所需数据时遇到了很多困难。数据是下面格式的.txt文件(附加文件),并在大(100 Mb)文件中重复:
温度0x100
部件号0x5A6A111F
5626 0 PASS DC_VoLevels.4 GPIO_32 312 1.0000 V 3.1638 V 3.3000 V -4.0000 mA 0
网站排序箱子
------------------------------------
0 123 4
我需要创建一个包含2列和标题的数据表,部件ID和Bin以及下面列出的数据:
部件ID Bin
0x5A6A111F 4
我可以提取部件ID,但下面的Bin和数字是我遇到的问题。任何帮助将非常感谢。
仁
导入这样的数据很棘手,但可以通过逐行读取文件,检查关键字以确定如何处理数据来完成。有关详情,请参阅下面的示
// load the file to be imported as a string
str = Load Text File( "$downloads\SampleFile.jsl" );
// create a table to add to
nt = New Table( "Example",
New Column( "PartID", "Character" ),
New Column( "Bin", "Numeric" )
);
// create a list with strings of each line of data
lines = Words( str, "\!N" );
// loop through each line of the file
for(i=1,i<=nitems(lines),i++,
if( // If the line starts with PART ID,
starts with(lines[i], "PART ID" ),
// it's the start of a new row
nt << add rows(1);
// grab the PartID at the end of the line
nt:PartID = Word( -1, lines[i] );
,
// if it starts with a bunch of dashes
starts with(lines[i], "---" ),
// the next line must contain column values
// so grab them and split them by spaces
colVals = Words( lines[i+1], " " );
// set the Bin column to the value in the third position
nt:Bin = colVals[3];
);
)
该脚本创建下表:
