Sto cercando di scrivere JSL per inserire più file e concatenarli insieme, ma ho alcuni file in cui le intestazioni iniziano nella riga 2 e alcuni file in cui l'intestazione inizia nella riga 3. Non sono a conoscenza di quali file abbiano intestazioni in righe diverse e sto cercando di evitare di doverli aprire tutti per scoprirlo. C'è un modo per scrivere JSL per cercare l'intestazione della prima colonna (Time) e iniziare a leggere lì?
File simili a CSV? Le linee extra all'inizio possono essere facilmente riconosciute? Tutto vuoto? Parole chiave standard? È possibile utilizzare uno script per leggere i primi N byte del file e decidere quante righe deve saltare l'importazione CSV. Guarda la funzione LoadTextFile per eseguire l'apertura preliminare.
Sì, sono file CSV.Alcuni hanno la prima riga con una data, la seconda riga con un VIN, quindi iniziano le intestazioni.Altri hanno la prima riga con la data, quindi iniziano le intestazioni.Puoi postare un esempio della sceneggiatura a cui ti riferisci?
Qualcosa come questo.
// pick a test case...
f = savetextfile("$temp\deleteme.csv","1jan2000\!ntime,x,y,z\!n101,1,2,3\!n101,4,5,6");
//f = Save Text File( "$temp\deleteme.csv", "1jan2000\!nVIN\!ntime,x,y,z\!n102,1,2,3\!n102,4,5,6" );
text = Load Text File( f );
// count newlines before "time"
newline = "\!n\!r" | "\!r\!n" | "\!n" | "\!r";
n = 0;
Pat Match( // there are a lot of ways you could count newlines before "time"
text, // use the pattern matcher to loop through the text
Pat Pos( 0 ) +
Pat Repeat(
("time" + Pat Rem()) // found "time", skip to the end
| // OR...skip to the end of the line and count it
(Pat Break( "\!n\!r" ) + newline + Pat Test( n += 1; 1; ))
)
);
Show( n );
HEADERLINE = n + 1;
FIRSTDATALINE = n + 2;
Open(
f,
columns(
New Column( "time", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "x", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "y", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "z", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( HEADERLINE ),
First Named Column( 1 ),
Data Starts( FIRSTDATALINE ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
Grazie mille! Questo ha funzionato perfettamente per me e mi ha fatto risparmiare così tanto tempo aprendo tutti i file CSV per modificarli!