我想使用R中的cat函数在文本文件中打印以下行:
shebang line
for file in *.out; do sed $'s/Cluster/\\\n&/g' $file > "$(basename "$file" .out)_split.out2"; done
为此,我使用:
cat("shebang line","for file in *.out; do sed $'s/Cluster/\\\n&/g' $file > \"$(basename \"$file\" .out)_split.out2\"; done",file="output.txt",sep="\n",append=TRUE)
但是在output.txt中,我得到了:
shebang line
for file in *.out; do sed $'s/Cluster/\
&/g' $file > "$(basename "$file" .out)_split.out2"; done
似乎它会创建额外的换行符,并且不要在单引号内打印\ n。 考虑到我确实需要使用\ n作为分隔符,如何在不创建换行符的情况下按原样打印字符? 谢谢
答案 0 :(得分:0)
尝试:
cat("shebang line","for file in *.out; do sed $'s/Cluster/\\\\\\n&/g' $file > \"$(basename \"$file\" .out)_split.out2\"; done",file="output.txt",sep="\n",append=TRUE)