# How to pipe each descriptor to different script/program



## ivand58 (Sep 13, 2010)

Hi all 

is there a way (in sh or bash) to redirect each descriptor to different script/program

e.g. pipe *stdout* | grep pattern1 _and_ *stderr* | grep pattern2


----------



## phoenix (Sep 13, 2010)

You can redirect stderr to stdout and then pipe that output through grep:
`$ command 2>&1 | egrep -e "pattern1|pattern2"`


----------



## gordon@ (Sep 14, 2010)

Unix pipelines don't allow for a branch. If you want to do what you describe, you would be best off with something like:

```
command 2> /tmp/cmd.stderr | grep pattern1
grep pattern2 /tmp/cmd.stderr
```

I think that should do what you are looking for.


----------

