gpt4 book ai didi

r - 如何打印\n 作为文本而不在 R cat 中的引号内创建换行符

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:15 25 4
gpt4 key购买 nike

我想使用 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 作为分隔符,如何在不创建换行符的情况下按原样打印字符?谢谢

最佳答案

尝试:

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)

关于r - 如何打印\n 作为文本而不在 R cat 中的引号内创建换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com