$ 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 -name \ * .js -type f -exec sed -i.bak'/console\.log/d'{} +'可能更有效。 – jfs 2013-04-25 07:08:06
是的,起初它似乎是從提供的例子。但後來我注意到在grep中的任何地方,他沒有使用文件擴展名,或者沒有提到任何地方只有* js文件是目標。所以我決定不做任何事情,並跳過了-name選項。 – abasu 2013-04-25 07:12:44