从所有 *c 文件中删除第一个多行注释
我的目录中有很多c 文件。每个文件将以多行注释开头,如下所示,并以 include 开头,就像
#include<stdio.h>.
// This is a c File
// This File does sampling the frequency
/* This uses the logic ...
.....
.....
*/
#include<stdio.h>
我需要删除所有 .c 文件开头的所有注释行(如果存在)。有些文件不会有这些注释行。在这种情况下,它不应该执行任何操作。这应该只删除第一个多行注释。后续的多行注释应该保持原样。
如何在 Perl 或 shell 中执行此操作?
提前致谢
I have lot of c files in a directory. Each files will start with multi line comment like below and starts with include like
#include<stdio.h>.
// This is a c File
// This File does sampling the frequency
/* This uses the logic ...
.....
.....
*/
#include<stdio.h>
I need to remove all the comments line at the start of all the .c files if they are present. Some files will not have these comment lines. In that case, it should not do anything. This should remove only the first multi line comments. Subsequent multi line comments should be as it is.
How to do this in perl or shell?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您确定所有文件都以包含开头,则可以在导入之前删除所有行:
If you are sure that all files start with an include, you could remove all lines before the import:
...或者:
...并且如果您只想对第一个多行注释执行此操作,请将范围的匹配分隔符从大括号更改为“?”字符,读起来像这样:
...or alternatively:
...AND if you only want to do this for the first multi-line comment, change the match delimiters of the range from curly braces to the "?" character, to read like this:
如果
#include
可以被视为一个阻止者,我有一个非常简单的解决方案:请注意,我必须更改初始的
#include
以便脚本正常工作。对我来说,如果我想要多行注释,最简单的解决方案是将'*/'
作为我的记录分隔符,而不是在各行上进行大量切换。但是前瞻需要缓冲并提出了一个更混乱的解决方案:
I had a pretty easy solution, if
#include
could be considered a stopper:Notice that I had to change the initial
#include
so that the script works. It seemed simple to me that if I wanted multi-line comments, the simplest solution was to make'*/'
my record separator, instead of doing a lot of switching on the individual lines.But the lookahead, requires buffering and made a messier solution: