<?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 Read CSV line by line to find where data starts in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476889#M72135</link>
    <description>&lt;P&gt;I need to load aCSV file which might be in number of different formats. And I need to find what line my data starts on. I know that the column names start after a certain line, let's say "[Data starts here]".&lt;/P&gt;&lt;P&gt;This is what I do:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ex = Load Text File(
	filePath
);
words = Words( ex, "\!n\!r" );
headersLocation = Loc(words, "[Data starts here]");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then I use headersLocation+1 to specify where my headers start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem happens when I have an empty line in my CSV file:&lt;/P&gt;&lt;PRE&gt;line1
line2

[Data Starts Here]
Header1, header2
0,0
1,1&lt;/PRE&gt;&lt;P&gt;When I break this file into words, line "[Data STarts Here]" will be the third one, Loca() function will give me 3 in this case, while in reality it's 4th line.&lt;/P&gt;&lt;P&gt;So when breaking file by Words function - that empty line just doesn't make it into the list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I don't know how many empty lines I may have in the file before data starts.&lt;/P&gt;&lt;P&gt;How do I go about it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can break by either "\!n" or "\!r" only, and then use Left() or Right() in a for loop to remove the remaining special symbol, but it seems too brute force and not very optimal and I'm not sure it is correct. Something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {value, index}, words, words[index] = Right(value, Length(value)-1););&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The whole script being:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ex = Load Text File(
	filePath
);
words = Words( ex, "\!n\!r" );
For Each( {value, index}, words, words[index] = Right(value, Length(value)-1););
headersLocation = Loc(words, "[Data starts here]");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then it seems to be working. But is this the best and even a correct solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 16:56:17 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2023-06-09T16:56:17Z</dc:date>
    <item>
      <title>Read CSV line by line to find where data starts</title>
      <link>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476889#M72135</link>
      <description>&lt;P&gt;I need to load aCSV file which might be in number of different formats. And I need to find what line my data starts on. I know that the column names start after a certain line, let's say "[Data starts here]".&lt;/P&gt;&lt;P&gt;This is what I do:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ex = Load Text File(
	filePath
);
words = Words( ex, "\!n\!r" );
headersLocation = Loc(words, "[Data starts here]");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and then I use headersLocation+1 to specify where my headers start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem happens when I have an empty line in my CSV file:&lt;/P&gt;&lt;PRE&gt;line1
line2

[Data Starts Here]
Header1, header2
0,0
1,1&lt;/PRE&gt;&lt;P&gt;When I break this file into words, line "[Data STarts Here]" will be the third one, Loca() function will give me 3 in this case, while in reality it's 4th line.&lt;/P&gt;&lt;P&gt;So when breaking file by Words function - that empty line just doesn't make it into the list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I don't know how many empty lines I may have in the file before data starts.&lt;/P&gt;&lt;P&gt;How do I go about it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can break by either "\!n" or "\!r" only, and then use Left() or Right() in a for loop to remove the remaining special symbol, but it seems too brute force and not very optimal and I'm not sure it is correct. Something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {value, index}, words, words[index] = Right(value, Length(value)-1););&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The whole script being:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ex = Load Text File(
	filePath
);
words = Words( ex, "\!n\!r" );
For Each( {value, index}, words, words[index] = Right(value, Length(value)-1););
headersLocation = Loc(words, "[Data starts here]");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then it seems to be working. But is this the best and even a correct solution?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:56:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476889#M72135</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-09T16:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV line by line to find where data starts</title>
      <link>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476928#M72138</link>
      <description>&lt;P&gt;Do you need the location for JMP's data import platform? If you have no need for the data before [Data Starts Here], you could just drop it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
csv = "line1
line2

[Data Starts Here]
Header1, header2
0,0
1,1
";

string_to_search = "[Data Starts Here]";
data_start_idx = Contains(csv, string_to_search);

data_str = Substr(csv, data_start_idx + Length(string_to_search) + 1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you need the JMP's import, you can use Char To Blob() with the string you now have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open(
	Char To Blob(data_str),
	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(1),
		Data Starts(2),
		Lines To Read("All"),
		Year Rule("20xx")
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Apr 2022 07:56:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476928#M72138</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-04-07T07:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Read CSV line by line to find where data starts</title>
      <link>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476929#M72139</link>
      <description>&lt;P&gt;Hmmm... Interesting suggestion. Let me try it. It might be easier after all.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 08:02:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Read-CSV-line-by-line-to-find-where-data-starts/m-p/476929#M72139</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2022-04-07T08:02:54Z</dc:date>
    </item>
  </channel>
</rss>

