解析1000个脚本获取字符串的最佳方式



我从一个前雇员那里继承了代码,我需要识别他用exit 0在顶部禁用的脚本。

如果我在脚本上执行head -2 load_db.ksh | tail -1 | grep hello,这工作得很好。我在脚本的第二行看到exit 0语句。

我如何为近900个脚本自动化这个?我试着使用find,但它出错了

find . -name "*.ksh" -exec head -2 '{}' | tail -1 |grep exit ;
grep: ;: No such file or directory
find: missing argument to -exec

我找不到语法错误

您当前正在将find的输出定向到tail,尝试如下:

find . -name "*.ksh" -exec sh -c "head -2 '{}' | tail -1 | grep exit" ;  

一个非常类似的替代方法是(这将返回需要您注意的文件列表):

    find . -name "*.ksh" |xargs -ifile sh -c "head -n 2 file | grep -q exit && echo file"

最新更新