嗨,
我在從文本文件中提取所需數據時遇到了很多困難。數據是下面格式的.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];
);
)
該腳本創建下表:
