Howaboutこの:
grep -ERn '^[[:space:]]*//' root_directory
-E
は '拡張' の用途が-R
はそれが
-n
は、あなたが次に行番号
でfilnamesをすることができます印刷したディレクトリを再帰的に作る
を正規表現このリストを簡単に処理して連続した一致を探すことができます。行番号が出力行ごとに1つずつ増加します。
これは、あなたがこのようなラインと一致したくない前提としています
int x = foo; // some comment
をしかし、完全にのみ行はコメント:
// this is a comment
を更新:
上記の出力を処理する短いPythonスクリプトですgrep
:
import sys
filenames_of_interest = set()
filename = None
prev_line_num = 0
comment_count = 0
for line in sys.stdin.readlines():
this_filename, line_num, _ = line.split(':',2)
line_num = int(line_num)
if this_filename != filename:
comment_count = 0
filename = this_filename
elif line_num != prev_line_num + 1:
comment_count = 0
prev_line_num = line_num
comment_count += 1
if comment_count > 20:
filenames_of_interest.add(filename)
print "files with blocks of comments:"
for i in filenames_of_interest:
print ' ', i
それは正しく、名前にコロンを使用してファイルを処理しませんが、それが問題だ場合に対処するために変更することが難しいことではありません。
出典
2011-10-18 17:15:00
jwd
"[[EclipseでJavaファイル全体でコメントアウトされたコードをすばやく見つけることはできますか?](http://stackoverflow.com/questions/4144213/is-there-a-quickway-to- find-all-the-out-code-across-java-files-in-ecl)」も同様の質問です。私は[この回答]にリンクしています(http://stackoverflow.com/questions/4144213/is-there-a-quickway-to-find-all-the-commented-out-code-across-java-files-in -ecl/7677471#7677471)。 – bbuser