2

I have inherited code from a former employee and I need to identify the scripts he disabled with exit 0 at the top.

If I do head -2 load_db.ksh | tail -1 | grep hello on a script, this works fine. I see the exit 0 statement at the second line of the script.

How can I automate this for nearly 900 scripts? I tried using find but it errs out

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

I cannot find the error in my syntax.

Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
Chris
  • 1,667
  • 6
  • 34
  • 52
  • possible duplicate of [How do I include a pipe | in my linux find -exec command?](http://stackoverflow.com/questions/307015/how-do-i-include-a-pipe-in-my-linux-find-exec-command) – zmo May 13 '14 at 17:36
  • This does work `find . -name "*.ksh" -exec sh -c "head -v -n2 '{}' | tail -v -n 1 | grep -H '^exit 0'" \;` but it does not display the filename matching the pattern. How can I accomplish that? – Chris May 13 '14 at 20:25

2 Answers2

2

You are currently directing the output of find to tail, try this:

find . -name "*.ksh" -exec sh -c "head -2 '{}' | tail -1 | grep exit" \;  
ebo
  • 2,717
  • 1
  • 27
  • 22
0

A very similar alternative would be (this will return actualy the list of files which need your attention):

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