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
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
jim holtman wrote:
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-', '',