%22%20text.txt.png)
我正在嘗試提取 Java 註解開始或結束的行:
我所擁有的是:
egrep "(/** | /* | */ | **/)" text.txt
我注意到這適用於所有行(例如 /* comment */),除了那些包含僅有的/*、/**、**/ 或 */ 且其前後沒有任何內容。
為什麼是這樣?
答案1
您的模式egrep "(/** | /* | */ | **/)" text.txt
包含明確的空格;嘗試沒有它們:egrep "(/**|/*|*/|**/)" text.txt
答案2
您在模式中包含空格,並且忘記了以 開頭的註解行//
。
和:
egrep "(/\*\*|/\*|\*/|\*\*/|//)" text.txt
我看到所有開始或結束註解的行,包括僅包含標記的行。例如...
文字.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 */
/*
*/
/**
**/