Hola,
Tengo muchas dificultades para extraer los datos que necesito de un archivo de texto. Los datos son un archivo .txt de formato a continuación (archivo adjunto), y se repite en un archivo grande (100 Mb):
Temperatura 0x100
ID DE PARTE 0x5A6A111F
5626 0 PASE DC_VoLevels.4 GPIO_32 312 1.0000 V 3.1638 V 3.3000 V -4.0000 mA 0
Clasificación del sitio Compartimiento
------------------------------------
0 123 4
Necesito crear una tabla de datos con 2 columnas y encabezados ID de pieza y Bandeja y los datos que se enumeran a continuación:
ID de la pieza
0x5A6A111F 4
Puedo extraer la ID de la pieza, pero con la que estoy teniendo problemas es con la Papelera y el número a continuación. Cualquier ayuda sería muy apreciada.
Jen
Importar datos como este es complicado, pero se puede hacer leyendo el archivo línea por línea, buscando palabras clave para determinar qué hacer con los datos. Vea el ejemplo a continuación para más detalles.
// 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];
);
)
Este script crea la siguiente tabla:
