title: Regex operations on Javascript functions
body: <p>I'm trying to find function names in Javascript and insert the following code </p>
  
  <pre><code>var functionName = arguments.callee.toString().substr('function '.length);
  functionName = functionName .substr(0,functionName .indexOf('('));
  console.log(functionName);
  </code></pre>
  
  <p>This will write the name of the function to the console as it's called. I am not having much luck with this. I've been trying variants of this with sed.exe:</p>
  
  <pre><code>sed "{/function/ s/$/\var ownName = arguments.callee.toString().substr('function '.length);ownName = ownName.substr(0,ownName.indexOf('('));console.log(ownName);/}" *.js
  </code></pre>
  
  <p>This is just in the format <code>sed "/elephant/ s/$/\&amp;castle" *.js</code></p>
  
  <p>Anyone have any idea how I can send what I'm appending to the next line, rather than on the same line as function? Also, how can I imlement the following (but in sed.exe) to avoid anonymous function and eval functions??</p>
  
  <pre><code>grep -Eho "^s*function w+" *.js | sort
  </code></pre>
  
  <p>Thanks for the help.</p>