gpt4 book ai didi

c - 脚本 : insert an additional #include after the last #include in many, 许多文件

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:28 25 4
gpt4 key购买 nike

有那么一瞬间,我希望能够摆脱 seda\ 命令,但是 sed(无论如何在我手中)并不是真正喜欢保持状态(在每个 #include 之后插入)。

那么有没有办法用 sed 做到这一点?有没有一种聪明的方法来做到这一点?

如果可以的话,我会求助于编写一个常规的 Python/Ruby 脚本,但这似乎是某个人可能在某个时候遇到过的问题。

最佳答案

在应用 sed 之前,您可以使用命令 tac 逐行反转文件,然后让 sed 执行插入而不是追加。当然还要确保 sed 只执行一次插入。像这样:

tac file | sed '1,/#include/ {/#include/i\
#include whatever
}' | tac

这应该可以解决问题。

关于c - 脚本 : insert an additional #include after the last #include in many, 许多文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13063725/

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