gpt4 book ai didi

linux - 如何从每个具有匹配文本的文件中删除行?

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

$ grep "console.log" * -R
account/db.js: console.log(err);
account/db.js: console.log(info);
account/db.js: console.log(err);
account/db.js: console.log(err2);
account/controller.js: console.log(covers);
account/controller.js: console.log(req.api_user);
account/controller.js: console.log(code);
account/controller.js: console.log(user);
account/helper.js: console.log(err);
messages/db.js: console.log("Error " + err);
messages/helper.js: console.log('No email notify.');
messages/helper.js: console.log(msg_body);
messages/helper.js: console.log(message.sid);
messages/helper.js: console.log(message.dateCreated);
messages/helper.js: console.log(error);
products/controller.js: console.log(product);
products/controller.js: console.log(product);
products/helper.js: console.log(data)
products/helper.js: console.log('removing index....');
profile/db.js: console.log(err);
profile/db.js: console.log(info);
profile/db.js: console.log(err);
profile/controller.js: console.log("sending phone confirmation text...");
profile/helper.js: console.log(message.sid);
profile/helper.js: console.log(message.dateCreated);
profile/helper.js: console.log(error);
receiver/controller.js: console.log(from);
receiver/controller.js: console.log(body);
receiver/controller.js: console.log(from_email);
receiver/controller.js: console.log(to_id_gen);
receiver/controller.js: console.log(finalbody);
receiver/controller.js: console.log(result);
reviews/db.js: console.log(err);
reviews/db.js: console.log(results);
reviews/controller.js: console.log(review);
reviews/controller.js: console.log(review_id);
search/controller.js: console.log(JSON.stringify(data.hits.hits, null, 4));

如您所见,在我编写代码时,我到处都在执行 console.log。

现在,我想删除所有这些行。我不想手动进入每个文件来删除它们。相反,我想通过命令来完成。

类似于grep "console.log"* -R,我如何做同样的事情但递归地删除那些行? (从我的当前目录一直查看树下的每个文件)

最佳答案

尝试find 寻找这样的东西。试试 find 。 -type f -exec sed -i '/console\.log/d' {}\; 但您可能对使用 -i.bak 而不是 -i 感兴趣 保留备份副本

关于linux - 如何从每个具有匹配文本的文件中删除行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16206233/

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