title: Pipe Find command "stderr" to a command
body: <p>Hi I have a peculiar problem and I'm trying hard to <strong>find</strong> (pun intended) a solution for it.</p>
  
  <pre><code>$&gt; find ./subdirectory -type f 2&gt;&gt;error.log
  </code></pre>
  
  <p>I get an error, something like, "find: ./subdirectory/noidea: Permission denied" from this command and this will be redirected to <strong>error.log</strong>.</p>
  
  <p>Is there any way I can pipe the <em>stderr</em> to another command before the redirection to <strong>error.log</strong>?</p>
  
  <p>I want to be able to do something like</p>
  
  <pre><code>$&gt; find ./subdirectory -type f 2 | sed "s#\(.*\)#${PWD}\1#" &gt;&gt; error.log
  </code></pre>
  
  <p>where I want to pipe only the <strong>stderr</strong> to the <strong>sed</strong> command and get the whole path of the <em>find command error</em>.</p>
  
  <p>I know piping doesn't work here and is probably not the right way to go about.</p>
  
  <p>My problem is I need both the <em>stdout</em> and <em>stderr</em> and the both have to be processed through different things simultaneously.</p>
  
  <p>EDIT:
  Ok. A slight modification to my problem.</p>
  
  <p>Now, I have a shell script, <strong>solve_problem.sh</strong></p>
  
  <p>In this shell script, I have the following code</p>
  
  <pre><code>ErrorFile="error.log"
  for directories in `find ./subdirectory -type f 2&gt;&gt; $ErrorFile`
  do
      field1=`echo $directories | cut -d / -f2`
      field2=`echo $directories | cut -d / -f3`
  done
  </code></pre>
  
  <p>Same problem but inside a shell script. The "find: ./subdirectory/noidea: Permission denied" error should go into <strong>$ErrorFile</strong> and <em>stdout</em> should get assigned to the variable <em>$directories</em>.</p>