Best way to parse 1000 scripts for a string?
I have inherited code from a former employee and I need to identify the scripts he disabled with exit 0 at the top.
After *many* trials and errors, I finally got this to work Code:
alan@p33 => find . -name "*.ksh" -exec sh -c "head -v -n2 '{}' | tail -v -n 1 | grep -H '^exit 0'" \; |
Just use the printf parameter of find:
Code:
find . -name "*.ksh" -printf "%f " -exec sh -c "head -v -n2 '{}' | tail -v -n 1 | grep -H '^exit 0'" \; |
Quote:
|
Well, i created 2000 test files, randomly with exit 0 in the top of them, and i was able to work with the output. ie, yes they were all listed, but only those with exit 0 had the text 'standard input' next to them.
How bout this: type out the exact output you would like to see, as an example. Then we can tell you what commands to use to format your output in that way. e.g Code:
FILENAME THAT HAS 'exit 0' IS: test0001.ksh !!!! (standard input):exit 0 |
Quote:
load_db.ksh :exit 0 run_report.ksh :exit 0 backup_report.ksh :exit 0 That's it. |
Ok. You can port this to ksh or sh or whatever,. but in bash(which is what i have to test with, sorry) this will work:
Code:
grep -Rn '^exit 0' *.ksh | grep ':1:\|:2:\|:3:' Code:
test001.ksh:1:exit 0
|
Quote:
|
From the current examples of output it would appear all the scripts are in the current directory, so as an alternative:
Code:
awk 'FNR==2 && /exit 0/{print FILENAME,":exit 0"}' *.ksh |
All times are GMT -5. The time now is 03:53 PM. |