Created
October 20, 2016 03:28
-
-
Save nemo-kaz/90bddd3039f3d82b87599867a6d78a5f to your computer and use it in GitHub Desktop.
recursively grep with one or two keywords.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g100pon recursively grep various filetype files with one or two keywords | |
// lastly invoke Hidemaru editor | |
startDir = "." | |
filePattern = /(\.asm.*$|\ | |
\.awk$|\ | |
\.bat$|\ | |
\.BMS$|\ | |
\.c$|\ | |
\.cbl.*$|\ | |
\.cl.*$|\ | |
\.cmd$|\ | |
\.CPY$|\ | |
\.csv$|\ | |
\.dspf$|\ | |
\.groovy$|\ | |
\.h$|\ | |
\.java$|\ | |
\.jcl$|\ | |
\.js$|\ | |
\.mac$|\ | |
\.pco$|\ | |
\.PGM$|\ | |
\.pl$|\ | |
\.properties$|\ | |
\.rpg.*$|\ | |
\.rst$|\ | |
\.sh.*$|\ | |
\.sql.*$|\ | |
\.src$|\ | |
\.stdl$|\ | |
\.text$|\ | |
\.txt$)/ | |
pattern0= args[0] | |
pattern = "(?i)"+args[0] | |
if (args.length > 1) { | |
patternb="(?i)"+args[1] | |
println pattern0 | |
pattern0=args[0]+"_"+args[1] | |
println pattern0 | |
} | |
enc = "windows-31j" | |
cleanPath="" | |
log = new File("Z:\\${pattern0}.search") | |
log.write("") | |
new File(startDir).eachFileRecurse { file -> | |
if (file =~ filePattern) { | |
file.eachLine(enc) { line, count -> | |
if (((args.length==1) && (line =~ pattern)) || ((args.length==2) && (line =~ pattern) && (line=~ patternb))) | |
{ | |
cleanPath= file.getAbsolutePath() //.replaceAll(/(.*)\\\.\\(.*)/) {m0,m1,m2 ->m1 m2 } | |
cleanPath =cleanPath.replace("\\.","") | |
println "${cleanPath}(${count}):${line}" | |
log.append("${cleanPath}(${count}):${line}\n") | |
} | |
} | |
} | |
} | |
Thread.sleep(500) | |
"Hidemaru.exe Z:\\${pattern0}.search".execute() | |
// "c:\\TOOL\\Hidemaru\\Hidemaru.exe Z:\\${pattern0}.search".execute() | |
// (?i) = case insensitive search |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment