gpt4 book ai didi

替换文本文件中的第 n 行

转载 作者:行者123 更新时间:2023-12-04 00:15:32 24 4
gpt4 key购买 nike

如何替换 R 中文本文件的第 n 行?

最佳答案

替换第三行:

$ cat junk.txt
sic transit
gloria mundi
temeo danoas
et dona ferentes

这样做:
> latin = readLines("junk.txt",-1)
> latin[3]="per ardua ad astra"
> writeLines(latin,"junkout.txt")

并得到:
$ cat junkout.txt 
sic transit
gloria mundi
per ardua ad astra
et dona ferentes

您可以 writeLines(latin,"junk.txt")并根据需要覆盖输入文件。

关于替换文本文件中的第 n 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756353/

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