【发布时间】:2018-09-06 08:37:38
【问题描述】:
到目前为止,我这样做了,但它并没有打印出我想要的内容。先感谢您。
$ sed -n -e "/\(*\)/g" c_comments | sed -n '/\/\*/p; /^ \*/p' c_comments |sed -n '/[[:blank:]]/p' c_comments
这是文本文件 c_cmets,我想提取 c_style 注释和 C++ cmets。 // 包含各种 C 和 C++ 样式 cmets 示例的文件
/* simple C style comment on one line with no code */
x = 5*3; /* Example comment following code */
/* comments do not have to begin at the line beginning */
/* And you can have empty comments like the next one */
/**/
/* comments with code following the comment (not possible with C++ style)
*/ x = w * u/y/z;
// As shown below you can have what appear to comments embedded in a
string
// The line below should be counted as code
printf(" This output string looks like a /* comment */ doesn't it?\n");
/* ---- Example of a multiline
C style comment */
c++; // C ++ style comment following code
c=a/b*c; /* comment between two pieces of code */ w = a*b/e;
/* This is a multiline c style comment. This
comment covers several
lines.
------*/
a = b / c * d;
/* -----------End of the file ---------------*/
【问题讨论】:
-
如果您将输入管道输入到
sed,您不应该给它一个文件名参数。当它得到一个文件名参数时,它会忽略标准输入。 -
您可以使用一个
sed命令和多个-e选项来执行多个不同的操作。 -
C 和 C++ 都使用相同的注释样式。你觉得有什么区别?
-
那么你的建议是什么?你的意思是只使用一次文件名吗
-
请注意,
sed正则表达式可以帮助您找到一些 cmets,但不是全部。 C/C++ 语法是一类比正则表达式可以解析的更复杂的语言。 CS的人都知道理论上的解释。
标签: linux unix sed command-line stream