Ciao,
Sto avendo un sacco di difficoltà nell'estrarre i dati di cui ho bisogno da un file di testo. Data è un file .txt di formato sottostante (file allegato) e viene ripetuto in un file di grandi dimensioni (100 Mb):
Temperatura 0x100
ID PART 0x5A6A111F
5626 0 PASS DC_VoLevels.4 GPIO_32 312 1.0000 V 3.1638 V 3.3000 V -4.0000 mA 0
Ordinamento sito Bidone
------------------------------------
0 123 4
Ho bisogno di creare una tabella dati con 2 colonne e intestazioni ID parti e Bin e dati elencati di seguito:
ID PART Bin
0x5A6A111F 4
Posso tirare l'ID della parte, ma il Bin e il numero sotto sono quelli con cui sto avendo problemi. Qualsiasi aiuto sarebbe molto apprezzato.
jen
L'importazione di dati come questa è complicata, ma può essere eseguita leggendo il file riga per riga, controllando le parole chiave per determinare cosa fare con i dati. Vedere l'esempio sotto per i dettagli.
// 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];
);
)
Questo script crea la seguente tabella:
