MathGroup Archive 2007

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

Search the Archive

Re: comments in import files

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74958] Re: comments in import files
  • From: "beheiger" <beheiger at hotmail.com>
  • Date: Fri, 13 Apr 2007 01:55:32 -0400 (EDT)
  • References: <eudd45$sdc$1@smc.vnet.net><eufr25$7rm$1@smc.vnet.net> <evhud0$33k$1@smc.vnet.net>

Thanks!

Andi

"Szabolcs" <szhorvat at gmail.com> schrieb im Newsbeitrag 
news:evhud0$33k$1 at smc.vnet.net...
>
> This is an old thread, but this might be useful for someone:
>
> I just figured out that you can Import[] from pipes directly, like
> this:
> Import["!grep -c ^# " <> filename, "Table"]
>
> Szabolcs
>
> http://documents.wolfram.com/mathematica/book/section-1.11.10
>
> On Mar 30, 10:04 am, "beheiger" <beheiger at hotmail.com> wrote:
>> Hi Szabolcs,
>>
>> I took up your approach in the following form:
>>
>> ImportTableNoComments[filename_] := Module[{tempfilename, res},
>>       tempfilename = filename <> "~";
>>       Run["grep", "-v", "^#", filename, ">", tempfilename];
>>       res = Import[tempfilename, "Table"];
>>       DeleteFile[tempfilename];
>>       Return[res];
>>       ];
>>
>> Works for me! Thanks,
>>
>> Andy
>>
>> "Szabolcs" <szhorvat at gmail.com> schrieb im 
>> Newsbeitragnews:eufr25$7rm$1 at smc.vnet.net...
>>
>> > On Mar 28, 11:39 am, "beheiger" <beheiger at hotmail.com> wrote:
>> >> Hi,
>>
>> >> I would like to know if Mathematica can handlecommentsin import files.
>> >> In particular, I would like to add lines ofcommentsto an
>> >> <emptyspace>-separated
>> >> ASCII table (say, "results.dat") that I produced with other programs.
>> >> However,
>> >> I can't seem to find anything on how to write thesecommentsin such a
>> >> way
>> >> that
>> >> Mathematica's function, used as
>>
>> >> Import["results.dat","Table"];
>>
>> >> does not complain. Help is appreciated.
>>
>> >> Regards, Andy
>>
>> > If nobody else posts a better solution (I hope that someone will), you
>> > can use the grep program to strip out thecomments, e.g.
>> > readTable[filename_] := (Run["grep", "-v", "^#", filename, ">", "c:\
>> > \temp\\tmpfile"]; Import["tmpfile", "Table"])
>>
>> > (This will remove lines starting with #.)
>>
>> > Of course you can also use Mathematica to read the file line by line
>> > and strip out thecomments, but it may be slow with large datasets.
>
>
> 




  • Prev by Date: Memory issue in SVD
  • Next by Date: Re: Beginner--Help on Listing Values
  • Previous by thread: Re: comments in import files
  • Next by thread: Re: Limiting range of variables when defining funxtions