Karin & Gerard Preusting
2003-Oct-02 19:57 UTC
[R] Search for a text string and write position related data to a file
Dear all, I just started using R today. What I need to do is find a text string in a (large) text file and than copy the some position related lines (or text) to an other text file. Is this possible with R? Example: Search string is: "Date" write line of <search string> +0, +2, +6, +7, +8, +9 ######################################## 1 Report of measured data 2 - 3 Date: 01-10-03 4 5 Time: 17:52:23 6 ------------ 7 =====8 ++++++ 9 x1=1.5 10 y1=2.9 11 x2=29 12 y2=704 .. .. 552 Date: 01-10-03 553 554 Time: 18:04:11 555 ------------ 556 =====557 ++++++ 558 x1=1.1 559 y1=1.9 560 x2=35 561 y2=870 .. .. etc ######################################## The new text file must contain: ######################################## Date: 01-10-03 Time: 17:52:23 x1=1.5 y1=2.9 x2=29 y2=704 Date: 01-10-03 Time: 18:04:11 x1=1.1 y1=1.9 x2=35 y2=870 etc ######################################## Is this possible?? Kind Regards, Gerard [[alternative HTML version deleted]]
Peter Dalgaard BSA
2003-Oct-02 20:56 UTC
[R] Search for a text string and write position related data to a file
"Karin & Gerard Preusting" <Karin at preusting.fol.nl> writes:> Dear all, > > I just started using R today. What I need to do is find a text > string in a (large) text file and than copy the some position > related lines (or text) to an other text file. Is this possible with > R?It's hardly a typical R application, but it can be done using a fairly straightforward while loop. See documentation for readLines, writeLines, and grep. (On Unix-like systems, tools like awk or perl will probably get the job done more quickly). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907