3

I am new to Mathematica, and I find that there may be a lot of ways of doing this. I was wondering which one might be the most general.

I am importing data from .txt files, resulting in a ragged array due to many lines containing parameters and other comments which I want to ignore. I just want to import the numbers, and ignore the comments.

I am using this:

Import["filename.txt", "TSV", "HeaderLines" -> 15]

I have no TrailerLines that I need to skip, however, there are many rows halfway through the data which I would like to remove. These lines all start with #, which makes me think that there is a way to just specify that any line starting with # be skipped.

Thanks a lot in advance to anyone who might be able to help me with this.

Rod
  • 3,318
  • 2
  • 24
  • 40
CSR
  • 33
  • 2

1 Answers1

1

You could delete them after Import.

DeleteCases[Import["filename.txt", "Data", "HeaderLines" -> 10], {_String, ___}]

or more precisely

DeleteCases[Import["filename.txt", "Data", "HeaderLines" -> 10],
  {_String?(StringMatchQ[#, "#*"] &), ___}]
Michael E2
  • 235,386
  • 17
  • 334
  • 747