%22%20text.txt.png)
Estou tentando extrair linhas que iniciam ou terminam um comentário Java:
O que eu tenho é:
egrep "(/** | /* | */ | **/)" texto.txt
Percebi que isso funciona para todas as linhas (como /* comment */), exceto aquelas que contêmapenas/*, /**, **/ ou */ e nada antes ou depois dele.
Por que é isso?
Responder1
Seu padrão egrep "(/** | /* | */ | **/)" text.txt
contém espaços explícitos; experimente sem eles:egrep "(/**|/*|*/|**/)" text.txt
Responder2
Você está incluindo espaços dentro do seu padrão e esquecendo as linhas de comentários que começam com //
.
Com:
egrep "(/\*\*|/\*|\*/|\*\*/|//)" text.txt
Vejo todas as linhas que iniciam ou terminam comentários, incluindo linhas que contêm apenas os tokens. Por exemplo...
texto.txt:
this should not be there
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
that
also */
not this
/*
*/
/**
**/
Saída:
// this should be there
/* and this too */
/** even this
should be there too **/
/* or
also */
/*
*/
/**
**/