<div dir="ltr">Hi,<div><br></div><div>I've a list of long files of numerical data ending with footer lines (beginning with #). I am using numpy.loadtxt to read the numbers, and loadtxt ignores these footer lines. I want the numpy code to read one of the footer lines and extract words from it. Is there a way to use loadtxt for this? If there weren't many files I could have used the line number (which keep varying between the files) of the footer line along with <i>linecache.</i> </div>
<div>Nevertheless there should be a generic way to do this in numpy?</div><div><br></div><div>As a workaround, I've tried using os.system along with grep. And I get the following output :</div><div>
<br></div><div><div><i>>>> os.system("grep -e 'tx' 'data.dat' ")</i></div><div><i> ## tx = 2023.06 </i></div><div><i>0</i></div><div><br></div><div>Why is there a 0 in the output? The file has no blank lines. </div>
<div> </div><div>Since I want the value 2023.06 in the numpy code for later use I tried to pipe the output to a variable:- </div><div><i>test = os.system(command)</i> </div><div>But that isn't working as <i>test</i> is getting assigned the value 0. </div>
<div>Tried <i>subprocess.call(['grep','-e','tx','data.dat'])</i> which is also ending up in the same fashion. </div><div><br></div><div>It'll be great if I can get to know (i) a way to read the footer lines (ii) to sort out the operation of os.system and subprocess.call output processing. </div>
<div><br></div><div>Thanks,</div><div>Resmi</div><div><br></div><div><br></div><div><br></div></div></div>