Note that there are some explanatory texts on larger screens.

plurals
  1. POPipe Find command "stderr" to a command
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload