我需要使用hadoop命令提取文件的时间刺激:
hadoop fs -ls /hdfs/data/adhoc//InterfacePublique-Controle-PUB_1EPSE-201808-PR-20190110-183844-indicateurs-PUB_1EPSE/* | awk '{timestamp= $6 " " $7;print timestamp}'
它可以给予
"2019-01-10 18:55"
但是当我使用这样的系统功能时,删除了 $ 6 $ 7
之间的引号x <- "/hdfs/data/adhoc//InterfacePublique-Controle-PUB_1EPSE-201808-PR-20190110-183844-indicateurs-PUB_1EPSE/*"
system(paste0("hadoop fs -ls ",x," | awk '{timestamp= $6 $7;print timestamp}' "),intern =TRUE)
返回:
2019-01-1018:55。第18小时和第10天发生冲突。
然后,如果我在hadoop表达式中添加引号。
system(paste0("hadoop fs -ls ",x," | awk '{timestamp= $6 " " $7;print timestamp}' "),intern =TRUE)
显示错误
意外令牌$ 7;打印时间戳记
请问该如何解决?
答案 0 :(得分:1)
您可以使用stringr
和lubridate
提取时间戳记:
x <- "/hdfs/data/adhoc//InterfacePublique-Controle-PUB_1EPSE-201808-PR-20190110-183844-indicateurs-PUB_1EPSE/*"
library(lubridate)
library(stringr)
ymd_hms(
str_extract(x, "(\\d{8}-\\d{6})")
)
[1] "2019-01-10 18:38:44 UTC"