I have a large file containing a table. To be specific, the table columns are aligned by spaces, and the rows are terminated by newlines.

I want to import only specific rows from this table. For example, I would like to import only those rows that have the string "Abc" as their 3rd entry.

How can I do this without importing the whole file?

  • 2
    $\begingroup$ str = OpenRead[fn]; "loop over" ReadLine[str]; Parse third element and compare to "Abc" and AppendTo based upon the comparison. $\endgroup$ – John Morganthau Feb 3 '15 at 23:18
  • 2
    $\begingroup$ @JohnMorganthau, if you don't know the number of lines you will fetch before you do so, it is better to use Reap and Sow instead of AppendTo ;) $\endgroup$ – Marius Ladegård Meyer Feb 4 '15 at 10:41
  • $\begingroup$ @MariusLadegårdMeyer I'm trying to create an example for this, but I'm not able to use the OpenRead function. Could you create a answer for this? $\endgroup$ – LCarvalho Dec 20 '16 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.