【发布时间】:2018-09-19 05:31:21
【问题描述】:
我有一个包含以下文本的文本文件。
/* a comment line in a C program */
printf("It is /* NOT a comment line */\n");
x = 5; /* This is an assignment, not a comment line */
[TAB][SPACE] /* another empty comment line here */
/* another weird line, but not a comment line */ y = 0;
我想删除以/* 开头并以*/ 结尾的行,仅使用 linux 命令。
为此,我编写了以下代码。
egrep "^/*.+*/$" small.txt
我将文本保存在我的small.txt 文件中。
但它会输出所有仅以 */ 结尾的行。
输出如下。
/* a comment line in a C program */
x = 5; /* This is an assignment, not a comment line */
[TAB][SPACE] /* another empty comment line here */
我想要的输出是
/* a comment line in a C program */
【问题讨论】:
-
跨多行的 cmets 怎么样?
-
先去掉空格和制表符,替换文件。
-
???替换文件?这是什么意思?