Issue
To find the classes having a private constructor I would like to use
git grep -lzP 'class\s+(\w++)[\s\S]*private\s+\1'
But it finds no result, however with the find command it finds
find */src/main/java -type f -exec grep -lzP 'class\s+(\w++)[\s\S]*private\s+\1' {} +
Solution
From git help grep
:
-z, --null
Output \0 instead of the character that normally follows a file name.
It only says that ASCII NUL will be added to output filenames. So, I don't think this is equivalent to grep -z
which treats "input and output data as sequences of lines, each terminated by a zero byte".
You can use grep -r
instead of find+grep
. I'd also recommend ripgrep for better performance.
Answered By - Sundeep Answer Checked By - Robin (WPSolving Admin)