我有一个脚本,使用R将sav文件转换为csv。挑战是我希望输出文件名与作为带有.csv扩展名的参数传递的文件名相同
语法是:R-Script.sh abc.sav
输出文件名应为abc.csv
这是R代码
argv <- commandArgs(TRUE)
Datafile <- argv[1]
library(foreign)
dataSPSS <- read.spss(Datafile, to.data.frame=TRUE)
dim(dataSPSS)
write.table(dataSPSS, file = "ifilename.csv", append = TRUE, quote = FALSE, sep = "|",eol = "\n", na = "", dec = ".", row.names = FALSE,col.names = TRUE, qmethod = c("escape", "double"))'
和调用R代码的包装器:
DataFile=$1
Rscript convert_sav-csv.r $DataFile
mv ifilename.csv $DataFile.csv '
输出文件名是abc.sav.csv。我希望它是abc.csv