我试图提取开始或结束Java注释的行:
我拥有的是:
“egrep "(/**而论)”text.txt“
我注意到,这适用于所有行(如/*注释*/),但只包含/*、/**、**/或*/ /的行除外,并且在此之前或之后不包含任何内容。
为什么会这样呢?
发布于 2015-11-06 14:33:19
您的模式egrep "(/** | /* | */ | **/)" text.txt包含显式空格;尝试不使用它们:egrep "(/**|/*|*/|**/)" text.txt
发布于 2015-11-06 14:41:26
您在模式中包含空格,并且忘记了以//开头的注释行。
通过以下方式:
egrep "(/\*\*|/\*|\*/|\*\*/|//)" text.txt我看到所有开始或结束注释的行,包括只包含标记的行。例如..。
text.txt:
this should not be there
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
that
also */
not this
/*
*/
/**
**/输出:
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
also */
/*
*/
/**
**/https://unix.stackexchange.com/questions/241255
复制相似问题