我有以下文件:
TAMF_Flight1.txt
TAMF_Flight1_profile.txt
TAMF_Flight2.txt
TAMF_Flight2_profile.txt
...
TAMF_Flight10.txt
TAMF_Flight10_profile.txt
TAMF_Flight11.txt
TAMF_Flight11_profile.txt
我应该在模式中加入什么才能获得:
TAMF_Flight1.txt
TAMF_Flight2.txt
...
TAMF_Flight10.txt
TAMF_Flight11.txt
或仅限:
TAMF_Flight1_profile.txt
TAMF_Flight2_profile.txt
...
TAMF_Flight10_profile.txt
TAMF_Flight11_profile.txt
答案 0 :(得分:1)
myfiles <- c('TAMF_Flight1.txt',
'TAMF_Flight1_profile.txt',
'TAMF_Flight2.txt',
'TAMF_Flight2_profile.txt')
grep( "TAMF_Flight[0-9]+[^_]", myfiles, value = TRUE)
# [1] "TAMF_Flight1.txt" "TAMF_Flight2.txt"
grep( "TAMF_Flight[0-9]+[_]", myfiles, value = TRUE)
# [1] "TAMF_Flight1_profile.txt" "TAMF_Flight2_profile.txt"
使用list.files()
list.files( path = ".", pattern = "TAMF_Flight[0-9]+\\.txt")
list.files( path = ".", pattern = "TAMF_Flight[0-9]+[_]")