[R] parsing a data file

Peter Wolf s-plus at wiwi.uni-bielefeld.de
Tue Apr 27 12:14:59 CEST 2004

Hello Tamas,
here is a starting point for your file parsing problem:

x2<-paste(x1,collapse=" ")
x3<-strsplit(x2, "RECORD")[[1]]

 [1] "BEGIN"   "RECORD"  "[first"  "record"  "data]"   "RECORD"  "[second"
 [8] "record"  "data]"   "RECORD"  "[third"  "record"  "data]"   "END"   

[1] "BEGIN RECORD [first record data] RECORD [second record data] RECORD 
[third record data] END"

[1] "BEGIN "                   " [first record data] "  
[3] " [second record data] "   " [third record data] END"

Peter Wolf

Tamas Papp wrote:

>I need to parse a data file (output of a measuring device) of the
>following format:
>BEGIN RECORD [first record data] RECORD [second
>record data] RECORD
>[third record data]
>Line breaks can (and do ;-() occur anywhere.  White space behaves very
>much like TeX, eg it is not important whether there are one or more
>spaces or linebreaks as long as there is one of them.  It is a text
>file, not binary.
>I need to extract the record data I marked with []'s, eg a vector such
>as c("[first record data]", "[second]", ...) would be nice as a
>What functions should I use for this?

More information about the R-help mailing list