我有以下格式的文件
*NEWRECORD
MH = Public Service Announcements as Topic
AQ = CL EC ES HI LJ SN ST TD UT
MN = L01.143.805
UI = D066308
*NEWRECORD
RECTYPE = D
MH = Public Service Announcements
MN = V02.736
MH_TH = NLM (2016)
ST = T170
DA = 20150701
基本上我的文件中有以上内容。我的目标是获得MH和MN的价值。该文件很大,主要采用上述格式。
答案 0 :(得分:1)
这样的东西会起作用吗?
d <- readLines('mydata.txt') # Read in data
out <- strsplit(d[grep(pattern = "MH|MN", x = d)], ' = ') #Look for those lines
do.call(rbind, out) # Bind it together
如果您想指出它来自哪个记录,您可能需要在将它们绑定在一起之前添加一个id列。