[英]How to delete // comment lines in all files in current folder and subfolders?
I need to delete all comments inside all script files in the current folder and sub folders. 我需要删除当前文件夹和子文件夹中所有脚本文件中的所有注释。 All comment lines start with //.
所有注释行均以//开头。 I want to delete the whole line
我要删除整行
find . -type f |xargs sed -i '\#^//#d'
the find part find all files, and the sed
part removes all lines starting with //
查找部分查找所有文件,而
sed
部分删除所有以//
开头的行
You can add -name
option in find
to do further filtering. 您可以添加
-name
在选项find
做进一步的筛选。 check man find
to get more useful information. 检查
man find
以获得更多有用的信息。
Your pattern contains slash /
, so with sed's default /pattern/d
you have to do some escaping. 您的模式包含斜线
/
,因此使用sed的默认/pattern/d
必须进行一些转义。 I used #
as delimiter to save that kind of works, and made the code easier to read. 我使用
#
作为分隔符来保存这种工作,并使代码更易于阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.