Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

How can I do a "grep -v" equivalent in Import[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91713] How can I do a "grep -v" equivalent in Import[]?
  • From: "Jason Ledbetter" <jasonbrent at gmail.com>
  • Date: Sat, 6 Sep 2008 02:07:29 -0400 (EDT)

Folk,
I have some data that is column formatted with a dual line header every few
lines; there may also be a variable number of lines between each header
output. The first line is readily identifiable with say "grep ^FOO", but the
second line in the header has white space at the beginning.

So what I need to do is the equivalent of "grep -v" to get rid of the
headers. My ultimate goal is to create a named List[] variable for each
"column" in the data, but I need to get rid of the headers.

Alternatively, I could regex match on the lines I DO want I think.. just
trying to wrap my head around how to do this in Mathematica.
For example, "egrep '^[0-9]+' foo.txt" gets me what I need in most shells...
I'd just like mathematica to do the same on import.

Do I need to process the import procedurally and dump the data I want into a
new Table[]?

I've been able to figure out how to get columnar data out of the import
using "foo=data[[All,{1}]" and so on (e.g., first column in the data)... I
just need to pre-filter the headers out.

I apologize for the junior level of the question. :/

Thanks!

-jbl



  • Prev by Date: LU Decomposition w/o Pivoting
  • Next by Date: CPU usage when AddOns is open in Help Browser
  • Previous by thread: Re: LU Decomposition w/o Pivoting
  • Next by thread: Re: How can I do a "grep -v" equivalent in Import[]?