MathGroup Archive 2006

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

Search the Archive

Re: Split a file into multiple files using a pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69771] Re: Split a file into multiple files using a pattern
  • From: "Raj" <rajanikanth at gmail.com>
  • Date: Fri, 22 Sep 2006 01:04:58 -0400 (EDT)
  • References: <eeqqnq$ooo$1@smc.vnet.net><eetvg8$aph$1@smc.vnet.net>

dh wrote:
> Hi Raj,
> this can best be done using regular expressions. Toward this aim, assume
> that your data is in the list dat. We convert this to a string, make the
> necessary replacements, split the string and transform it back to an
> expression. Thereby we introduce a marker "@" to indicate where the
> string should be split:
> t=ToString[dat];
> t=StringReplace[t,RegularExpression[",?(\\s*9,){3,300}"]->"}@{"];
> t=StringSplit[t,"@"] //ToExpression;
> The elements of t contain now the data to be written to the different files.
>
> Daniel
>
> Raj wrote:
> > hi!
> >
> > COuld somebody please tell me how can I do this in Mathematica: I have
> > a file of numbers containing -999.99 in places where there is missing
> > data.
> > I want to split the file into a number of files based on the criterion
> > that the number of consecutive - 999.99 are more than 18 .
> >
> > For example... if the file is of the form
> >
> > {1,2,3,4,{-999.99 repeated 18 or more times},5,6,7,8}
> > then I want the output to be file1.txt which contains {1,2,3,4} and
> > file2.txt which contains {5,6,7,8}
> >
> > Thanks,
> >
> > Raj
> >

Thanks to everybody who replied.

Please note that the code by Paul does exactly what I want. The other
codes dont seem to check if the number of consecutive -999.99's are
more then 18. I want to split the file only in the places where the
number of -999.99's are greater than 18.

Regards,

Raj


  • Prev by Date: Re: question about NDelayDSolve
  • Next by Date: Re: Re: could someone explain Mathematica's protests about division by zero here?
  • Previous by thread: Re: Split a file into multiple files using a pattern
  • Next by thread: TEXT SIZE 12 ?