我正在尝试从 Linux 拆分“ls -lrt”命令的输出。但它只占用一个空格作为分隔符。如果有两个空格,那么它将第二个空格作为值。所以我认为我需要将多个空间压制为一个。有人对此有任何想法吗?
> a <- try(system("ls -lrt | grep -i .rds", intern = TRUE))
> a
[1] "-rw-r--r-- 1 u7x9573 sashare 2297 Jun 9 16:10 abcde.RDS"
[2] "-rw-r--r-- 1 u7x9573 sashare 86704 Jun 9 16:10 InputSource2.rds"
> str(a)
chr [1:6] "-rw-r--r-- 1 u7x9573 sashare 2297 Jun 9 16:10 abcde.RDS" ...
>
>c = strsplit(a," ")
>c
[[1]]
[1] "-rw-r--r--" "1" "u7x9573" "sashare" ""
[6] "2297" "Jun" "" "9" "16:10"
[11] "abcde.RDS"
[[2]]
[1] "-rw-r--r--" "1" "u7x9573" "sashare"
[5] "86704" "Jun" "" "9"
[9] "16:10" "InputSource2.rds"
在下一步中,我只需要文件名,我使用了以下代码,效果很好:
mtrl_name <- try(system("ls | grep -i .rds", intern = TRUE))