複数のファイルを取り込んで連結する JSL を記述しようとしていますが、ヘッダーが 2 行目から始まるファイルもあれば、3 行目から始まるファイルもあります。どのファイルのヘッダーが別の行にあるかがわからず、調べるためにすべてのファイルを開く必要がないようにしたいと考えています。最初の列ヘッダー (Time) を探してそこから読み取りを開始するように JSL を記述する方法はありますか?
CSV のようなファイルですか? 先頭の余分な行は簡単に認識できますか? 全部真っ白? 定番のキーワード? スクリプトを使用してファイルの最初の N バイトを読み取り、CSV インポートでスキップする行数を決定できます。 LoadTextFile 関数を見て、予備的なオープンを行います。
はい、CSV ファイルです。最初の行に日付、2 行目に VIN、そしてヘッダーが始まるものもあります。他のものでは、最初の行に日付があり、その後ヘッダーが始まります。参照しているスクリプトの例を投稿していただけますか?
このようなもの。
// 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" )
)
);
どうもありがとうございます! これは私にとって完璧に機能し、すべての CSV ファイルを開いて編集する時間を大幅に節約できました。