Is this what you want?
> result <- readLines('/tempxx.txt')
> result
[1] "*NEW RECORD" "*ID-001" "*AB-text"
"" "*NEW RECORD"
[6] "*ID-002" "*AB-text"> result <- result[grep('^.ID-', result)] # select only ID lines
> result
[1] "*ID-001" "*ID-002"> sub('^.ID-', '', result)
[1] "001" "002"
On 1/28/06, Andrej Kastrin <andrej.kastrin@siol.net>
wrote:>
> Dear R useRs,
>
> is there any simple, build in function to match specific regular
> expression in data file and write it to a vector. I have the following
> text file:
>
> *NEW RECORD
> *ID-001
> *AB-text
>
> *NEW RECORD
> *ID-002
> *AB-text
> etc.
>
> Now I have to match all ID fields and print them to a vector:
> 001
> 002
> etc.
>
> I know that this is very simple with Perl or R-Perl interface, but if
> possible, I want to do that 'on the hard way'.
>
> Cheers, Andrej
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
--
Jim Holtman
Cincinnati, OH
+1 513 247 0281
What the problem you are trying to solve?
[[alternative HTML version deleted]]