<font face="Default Sans Serif,Verdana,Arial,Helvetica,sans-serif" size="2">Richard,<br><br>Perhaps this may help you:<br><font color="#b01813"><br>function</font> <font color="#4a55db">[</font><span style="font-weight: bold;"><font color="#834310">info</font></span><font color="#000000">, </font><span style="font-weight: bold;"><font color="#834310">header</font></span><font color="#000000">, </font><span style="font-weight: bold;"><font color="#834310">m</font></span><font color="#4a55db">]</font><font color="#5c5c5c">=</font><span style="text-decoration: underline;"><font color="#000000">parseFile</font></span><font color="#4a55db">(</font><span style="font-weight: bold;"><font color="#834310">fileName</font></span><font color="#4a55db">)</font> <pre style="font-family:Monospaced;font-style:normal;font-size:12.0;">    <font color="#000000">file_d</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">mopen</font><font color="#4a55db">(</font><span style="font-weight: bold;"><font color="#834310">fileName</font></span><font color="#000000">,</font><font color="#bc8f8f">"</font><font color="#bc8f8f">r</font><font color="#bc8f8f">"</font><font color="#4a55db">)</font>     <font color="#a020f0">for</font> <font color="#000000">line</font> <font color="#5c5c5c">=</font> <font color="#bc8f8f">1</font><font color="#ffaa00">:</font><font color="#bc8f8f">8</font>         <font color="#000000">lineToParse</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">mgetl</font><font color="#4a55db">(</font><font color="#000000">file_d</font><font color="#000000">,</font><font color="#bc8f8f">1</font><font color="#4a55db">)</font>         <font color="#000000">tks</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">tokens</font><font color="#4a55db">(</font><font color="#000000">lineToParse</font><font color="#000000">,</font><font color="#bc8f8f">"</font><font color="#bc8f8f">:</font><font color="#bc8f8f">"</font><font color="#4a55db">)</font>         <span style="font-weight: bold;"><font color="#834310">info</font></span><font color="#4a55db">(</font><font color="#000000">line</font><font color="#000000">,</font><font color="#bc8f8f">1</font><font color="#4a55db">)</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">stripblanks</font><font color="#4a55db">(</font><font color="#000000">tks</font><font color="#4a55db">(</font><font color="#bc8f8f">1</font><font color="#4a55db">)</font><font color="#4a55db">)</font>         <span style="font-weight: bold;"><font color="#834310">info</font></span><font color="#4a55db">(</font><font color="#000000">line</font><font color="#000000">,</font><font color="#bc8f8f">2</font><font color="#4a55db">)</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">stripblanks</font><font color="#4a55db">(</font><font color="#000000">tks</font><font color="#4a55db">(</font><font color="#bc8f8f">2</font><font color="#4a55db">)</font><font color="#4a55db">)</font>     <font color="#a020f0">end</font>     <span style="font-weight: bold;"><font color="#834310">header</font></span> <font color="#5c5c5c">=</font> <font color="#32b9b9">mgetl</font><font color="#4a55db">(</font><font color="#000000">file_d</font><font color="#000000">,</font><font color="#bc8f8f">1</font><font color="#4a55db">)</font>     <font color="#000000">k</font> <font color="#5c5c5c">=</font> <font color="#bc8f8f">1</font>     <font color="#a020f0">while</font> <font color="#5c5c5c">~</font><font color="#32b9b9">meof</font><font color="#4a55db">(</font><font color="#000000">file_d</font><font color="#4a55db">)</font>         <font color="#000000">lineToParse</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">mgetl</font><font color="#4a55db">(</font><font color="#000000">file_d</font><font color="#000000">,</font><font color="#bc8f8f">1</font><font color="#4a55db">)</font>         <font color="#000000">tks</font> <font color="#5c5c5c">=</font> <font color="#32b9b9">tokens</font><font color="#4a55db">(</font><font color="#000000">lineToParse</font><font color="#000000">,</font><font color="#bc8f8f">"</font><font color="#bc8f8f">,</font><font color="#bc8f8f">"</font><font color="#4a55db">)</font>         <span style="font-style: italic;"><font color="#64ae64">//pause</font></span>         <font color="#a020f0">for</font> <font color="#000000">i</font> <font color="#5c5c5c">=</font> <font color="#bc8f8f">1</font><font color="#ffaa00">:</font><font color="#bc8f8f">3</font>             <span style="font-weight: bold;"><font color="#834310">m</font></span><font color="#4a55db">(</font><font color="#000000">k</font><font color="#000000">,</font><font color="#000000">i</font><font color="#4a55db">)</font> <font color="#5c5c5c">=</font> <span style="text-decoration: underline;"><font color="#ae5cb0">eval</font></span><font color="#4a55db">(</font><font color="#000000">tks</font><font color="#4a55db">(</font><font color="#000000">i</font><font color="#4a55db">)</font><font color="#4a55db">)</font>         <font color="#a020f0">end</font>         <font color="#000000">k</font> <font color="#5c5c5c">=</font> <font color="#000000">k</font> <font color="#5c5c5c">+</font> <font color="#bc8f8f">1</font>     <font color="#a020f0">end</font>     <font color="#32b9b9">mclose</font><font color="#4a55db">(</font><font color="#000000">file_d</font><font color="#4a55db">)</font> <font color="#b01813">endfunction<br><br><br></font></pre><font face="Default Monospace,Courier New,Courier,monospace">-->[info,header,m] = parseFile("llom.txt")<br> m  =<br> <br>    1.498D+09    0.0086091    12.10613  <br>    1.498D+09    0.1577809    12.0754   <br>    1.498D+09    1.010268     11.93087  <br> header  =<br> <br> UTC TIME SEC  ,CH1 AMPS DC  ,CH2 VOLT DC     <br> info  =<br> <br>!PCB   007          !<br>!                   !<br>!ASM   000          !<br>!                   !<br>!LOT   00000        !<br>!                   !<br>!FW    1477971088   !<br>!                   !<br>!CH1   AMPS   10A   !<br>!                   !<br>!CH2   VOLT   60V   !<br>!                   !<br>!SMPL  0064 0125Hz  !<br>!                   !<br>!DESC  12V CU LOG   !</font><br><br><font color="#990099">-----"users" <users-bounces@lists.scilab.org> escreveu: -----</font><div style="padding-left:5px;"><div style="padding-right:0px;padding-left:5px;border-left:solid black 2px;">Para: Users mailing list for Scilab <users@lists.scilab.org><br>De: paul.carrico@free.fr<br>Enviado por: "users" <users-bounces@lists.scilab.org><br>Data: 19/06/2017 03:25 AM<br>cc: Richard llom <richard.llom@gmail.com><br>Assunto: Re: [Scilab-users] Advice needed on file parsing<br><br><!--Notes ACF <meta http-equiv="Content-Type" content="text/html; charset=utf8" />--> <div class="pre" style="margin: 0; padding: 0; font-family: monospace">Hi</div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> <p>I cannot say if the following is the best way to proceed, but when the number of columns differs, I always have a look to such functions in order to get the data: mopen/mgetl/grep/strindex and so on ... it need a bit of work.</p> <p>The previous method work when the file size is not huge because mgetl loads in memory all the file first - in case of huge files (I mean with millions of lines), I need to adopt another strategy (bash file using awk - grep - seb and so on tool) in order to have a text/matrix file in a right format ... nevertheless I do not get strings so the previous method may not work.</p> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace">Just a feedback</div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace">Paul</div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace"> </div> <div class="pre" style="margin: 0; padding: 0; font-family: monospace">Le 2017-06-18 23:10, Richard llom a écrit : <blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">Hello fellow scilab-users,<br> I'm writing a script to read and process files, which are constructed as<br> follows:<br> <file start><br> PCB: 007<br> ASM: 000<br> LOT: 00000<br> FW:  1477971088<br> CH1:  AMPS   10A<br> CH2:  VOLT   60V<br> SMPL: 0064 0125Hz<br> DESC: 12V CU LOG<br> UTC TIME SEC  ,CH1 AMPS DC  ,CH2 VOLT DC  <br> 1497812372.910, 8.609146E-03, 1.210613E001<br> 1497812373.895, 1.577809E-01, 1.207540E001<br> 1497812374.578, 1.010268E000, 1.193087E001<br> ... [snip]<br> <file end><br> <br> To process this file further, I need:<br> 1)<br> the first eight lines stored in pairs, e.g. <br> info(1,1) should yield "PCB" and info(1,2) should yield "007" (string is ok)<br> <br> 2)<br> line #9 (header), should be available as header(1)="UTC TIME SEC", etc...<br> <br> 3)<br> line 10+<br> these should be scanned in as a matrix.<br> <br> <br> I already tried csvread and msscanf (?), however with no luck so far...<br> <br> <br> So if someone could just point me to the apropiates function for each task.<br> I hopefully can take it then from there.<br> Thanks & cheers<br> richard<br> <br> <br> <br> --<br> View this message in context:<br> <a href="http://mailinglists.scilab.org/Advice-needed-on-file-parsing-tp4036587.html" target="_blank" rel="noreferrer">http://mailinglists.scilab.org/Advice-needed-on-file-parsing-tp4036587.html</a><br> Sent from the Scilab users - Mailing Lists Archives mailing list<br> archive at Nabble.com.<br> _______________________________________________<br> users mailing list<br> <a href="mailto:users@lists.scilab.org">users@lists.scilab.org</a><br> <a href="http://lists.scilab.org/mailman/listinfo/users" target="_blank" rel="noreferrer">http://lists.scilab.org/mailman/listinfo/users</a></blockquote> </div> <div><font size="2" face="Courier New,Courier,monospace">_______________________________________________<br>users mailing list<br>users@lists.scilab.org<br><a href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a><br></font></div></users-bounces@lists.scilab.org></div></div><div></div></font>