1

I'm trying to extract lines starting or ending a Java comment:

What I have is:

egrep "(/** | /* | */ | **/)" text.txt

I noticed that this works for all lines (such as /* comment */) except those that contain only /*, /**, **/ or */ and nothing preceding or following it.

Why is this?

2 Answers 2

1

Your pattern egrep "(/** | /* | */ | **/)" text.txt contains explicit spaces; try it without them: egrep "(/**|/*|*/|**/)" text.txt

0

You are including spaces inside your pattern, and you are forgetting the comment lines starting with //.

With:

egrep "(/\*\*|/\*|\*/|\*\*/|//)" text.txt

I see all lines that start or end comments, including lines that only contain the tokens. For example...

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
/*
*/
/**
**/

Output:

// this should be there
/* and this too */
/** even this
should be there too **/
/* or
also */
/*
*/
/**
**/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .