简体   繁体   English

如何删除//当前文件夹和子文件夹中所有文件中的注释行?

[英]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.

相关问题 从 Mac 上的命令行删除当前文件夹和所有子文件夹中的 .DS_STORE 文件 - Delete .DS_STORE files in current folder and all subfolders from command line on Mac 如何监控包含所有子文件夹和文件的文件夹? - How to monitor a folder with all subfolders and files inside? 在Linux上删除包含子文件夹和文件的文件夹 - Delete folder that contain subfolders and files on linux 在文件夹和子文件夹中查找所有文件的另一种方法 - Alternative way to find all files in a folder and subfolders 消除子文件夹,将所有文件移动到一个文件夹中 - Eliminating subfolders to move all files into one folder 在子文件夹中搜索文件中的字符串,然后删除删除匹配文件的父文件夹 - Search subfolders for string in files, and delete delete parent folder of matching file 如何从所有.xml文件中删除所有包含字符串的行? - How to delete all lines containing a string from all .xml files? 如何基于正则表达式递归查找当前文件夹和子文件夹中的所有文件 - How can I recursively find all files in current and subfolders based on regular expressions 如何根据通配符匹配递归查找当前文件夹和子文件夹中的所有文件? - How can I recursively find all files in current and subfolders based on wildcard matching? 如何递归地将文件夹及其所有子文件夹和文件设置为 drwxrwxrwx - How do I recursively set a folder and all of its subfolders and files to drwxrwxrwx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM