问题描述
我要删除一对匹配模式/ *和* /之间的所有行和内容。例如我的数据是
/*******/
/*Text1*/
/*Text2*/
/*******/
Text3/*Text4*/
Text5
/*
Text6
*/
我的输出应该是
Text3
Text5
我尝试了sed'// * /,/ * // d'test.txt,但没有用。
解决方法
这应该可以实现您想要的:
perl -0777 -ne 's[/\*.*?\*/][]gs; # Remove comments
s/\n\n+/\n/g; # Contract multipe newlines into one
s/^\n//g; print # Remove the first empty line and print
' < data
-0777
作为一个块读取整个文件