<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic JSL - Pulling in files with headers in different rows in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633269#M83165</link>
    <description>&lt;P&gt;I am trying to write JSL to pull in multiple files and concatenate them together, but I have some files where the headers start in row 2 and some files where the header starts in row 3.&amp;nbsp; I am unaware of which files have headers in different rows and I am trying to avoid having to open them all to find out.&amp;nbsp; Is there a way to write JSL to look for the first column header (Time) and start reading there?&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 16:10:26 GMT</pubDate>
    <dc:creator>AmandaStone</dc:creator>
    <dc:date>2023-06-09T16:10:26Z</dc:date>
    <item>
      <title>JSL - Pulling in files with headers in different rows</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633269#M83165</link>
      <description>&lt;P&gt;I am trying to write JSL to pull in multiple files and concatenate them together, but I have some files where the headers start in row 2 and some files where the header starts in row 3.&amp;nbsp; I am unaware of which files have headers in different rows and I am trying to avoid having to open them all to find out.&amp;nbsp; Is there a way to write JSL to look for the first column header (Time) and start reading there?&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:10:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633269#M83165</guid>
      <dc:creator>AmandaStone</dc:creator>
      <dc:date>2023-06-09T16:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - Pulling in files with headers in different rows</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633332#M83170</link>
      <description>&lt;P&gt;CSV-like files? Can the extra lines at the beginning be easily recognized? All blank? Standard keywords? You could use a script to read the first N bytes of the file and decide how many lines CSV import should skip. Look at the LoadTextFile function to do the preliminary open.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 14:12:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633332#M83170</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-19T14:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - Pulling in files with headers in different rows</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633337#M83171</link>
      <description>&lt;P&gt;Yes, they are CSV files.&amp;nbsp; Some have the first line with a date, second line with a VIN, then headers start.&amp;nbsp; Others have first line with date, then headers start.&amp;nbsp; Can you post an example of the script you are referring to?&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 14:15:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633337#M83171</guid>
      <dc:creator>AmandaStone</dc:creator>
      <dc:date>2023-05-19T14:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - Pulling in files with headers in different rows</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633343#M83172</link>
      <description>&lt;P&gt;Something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// 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" )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 14:47:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633343#M83172</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-19T14:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - Pulling in files with headers in different rows</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633438#M83178</link>
      <description>&lt;P&gt;Thank you so much! This worked perfect for me and saved me so much time opening all the CSV files to edit them!&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 17:20:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-Pulling-in-files-with-headers-in-different-rows/m-p/633438#M83178</guid>
      <dc:creator>AmandaStone</dc:creator>
      <dc:date>2023-05-19T17:20:12Z</dc:date>
    </item>
  </channel>
</rss>

