여러 파일을 가져와 함께 연결하기 위해 JSL을 작성하려고 하는데 헤더가 행 2에서 시작하는 일부 파일과 헤더가 행 3에서 시작되는 일부 파일이 있습니다. 어떤 파일이 다른 행에 헤더가 있는지 알 수 없습니다. 그리고 나는 알아내기 위해 그것들을 모두 열어볼 필요가 없도록 노력하고 있습니다. 첫 번째 열 헤더(시간)를 찾고 거기에서 읽기 시작하도록 JSL을 작성하는 방법이 있습니까?
CSV와 같은 파일? 처음에 여분의 줄을 쉽게 알아볼 수 있습니까? 모두 비어 있습니까? 표준 키워드? 스크립트를 사용하여 파일의 처음 N바이트를 읽고 CSV 가져오기에서 건너뛸 줄 수를 결정할 수 있습니다. 예비 열기를 수행하려면 LoadTextFile 함수를 살펴보십시오.
예, CSV 파일입니다.일부는 날짜가 있는 첫 번째 줄, 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 파일을 열어 편집하는 데 많은 시간을 절약해 주었습니다!