使用 R system() 函数时,意外标记 `(' 附近出现语法错误
这里我有多个文件,比如 3 个具有相同行和列的文件,现在我想从每个文件中提取第二列并将它们粘贴到一个新文件中。当我在 linux bash 中运行以下命令时,它起作用了。
paste <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text1.txt) <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text2.txt) <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text3.txt) > output.txt
当我尝试使用 R 脚本通过 system() 函数运行此命令时,
cmd = paste0("paste ", paste0("<(awk 'BEGIN{OFS=\"\t\"}(NR>1){print $2}' text", 1:3, ".txt) ", collapse = ""), " > output.txt", collapse = "")
system(cmd)
它返回错误:
syntax error near unexpected token `('
任何人都可以帮助我。感谢任何帮助。
Here I have multiple files say 3 files with same rows and columns, now I want to extract the second column from each file and paste them in a new file. When I run the following command in linux bash,its working.
paste <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text1.txt) <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text2.txt) <(awk 'BEGIN{OFS="\t"}(NR>1){print $2}' text3.txt) > output.txt
While when I try to use R script to run this command via system() function by
cmd = paste0("paste ", paste0("<(awk 'BEGIN{OFS=\"\t\"}(NR>1){print $2}' text", 1:3, ".txt) ", collapse = ""), " > output.txt", collapse = "")
system(cmd)
it returns error:
syntax error near unexpected token `('
Can anyone help me out. Appreciate any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
<()
仅在扩展 shell 中可用(ksh93、bash、zsh 等);system()
使用sh
。但是,您可以编写与sh
配合使用的等效脚本:<()
is only available in extended shells (ksh93, bash, zsh, etc); andsystem()
usessh
. However, you can write an equivalent script that works withsh
: