Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg69722] Re: Split a file into multiple files using a pattern
  • From: dh <dh at metrohm.ch>
  • Date: Thu, 21 Sep 2006 07:31:29 -0400 (EDT)
  • References: <eeqqnq$ooo$1@smc.vnet.net>

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
> 


  • Prev by Date: question about NDelayDSolve
  • Next by Date: Re: How to delete a row and a column in a matrix?
  • Previous by thread: Re: Split a file into multiple files using a pattern
  • Next by thread: Re: Split a file into multiple files using a pattern