I would like to write a loop to generate 22 R scripts with contents generated in echo. What went wrong in this loop that I could not get the 22 files with the corresponding content?
I tested echo "i want that file" > file.r
It works fine. Then I tested, it treated as two seperate process. First it echo the text, then it generated 22 empty files.
for i in `seq 1 22`; do
echo "a <- read.delim('file${i}.txt', header=T, check.names=FALSE);
library('splitstackshape');
loc1 <- cSplit(a, 'V1', ':');
rm(a);
out <- cbind.data.frame(loc1$V1_1, loc1$V1_2);
write.table(out, 'out_file${i}.txt', sep='\t', row.names=F, quote=F)";
> build_file${i}.r; done
Then I tried this.. still not working..
for i in `seq 1 22`; do
echo "a <- read.delim("file${i}.txt", header=T, check.names=FALSE);
library("splitstackshape");
loc1 <- cSplit(a, "V1", ":");
rm(a);
out <- cbind.data.frame(loc1$V1_1, loc1$V1_2);
write.table(out, "out_file${i}.txt", sep="\t", row.names=F, quote=F)";
cat > loc_chr${i}.r; done