Re: Repeat Data reading in one file
- To: mathgroup at smc.vnet.net
- Subject: [mg105789] Re: Repeat Data reading in one file
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sat, 19 Dec 2009 06:25:23 -0500 (EST)
On 12/18/09 at 6:23 AM, graser at gmail.com (graser) wrote: >On Dec 17, 7:27 am, Bill Rowe <readn... at sbcglobal.net> wrote: >>On 12/16/09 at 6:17 AM, gra... at gmail.com (graser) wrote: >>>I am posting my question.. The question is I have multiple files >>>with following data structure.. Header..1 Header..2 1 3.12 2. 2.54 >>You haven't asked a question nor made it clear what you want to do >>with the files you describe. Perhaps all you need is a pointer on >>how to read these files with Mathematica. If so, the function >>likely to be most useful to you is Import. Probably >>Import[filename,"Table"] >>will work. For details on using Import see the online documentation >>available in the Documentation Center. >My question was >1. Each data file has same structure like above.. >2. I want to take out only Numbers or I want to skip headers or comments. >3. In each file, there are a couple of lines of header 1 and multiple >data repeats with header 2. >But the number of repetition is different in different file. >4. So I want to save only the number data with mathematica.. >5. Import is not working at all.. When you say Import is "not working at all..." what do you mean? Not reading the file information? Or reading more than what you want? Assuming it is the later, then likely the simplest way to achieve your goal given the structure you've indicated would be data = Cases[Import[filename, "Table"], {_?NumericQ,__}] if you want data to be just the numeric data or headers = DeleteCases[Import[filename, "Table"], {_?NumericQ,__}] if you want to only retain the non-numeric lines. This should be adeguate for moderately sized files. If the files are really large, then this will be rather slow due to the overhead Import has and the fact you are reading in more of the file then you really need to. You can read only the stuff you want from the files by opening a stream and writing your own functions to read in the data making use of the built-in function Read. But this is definitely more work and is unlikely to be worthwhile for moderately sized files.