LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Pipe and background execution (https://www.linuxquestions.org/questions/linux-newbie-8/pipe-and-background-execution-655872/)

pn8830 07-15-2008 07:49 AM

Pipe and background execution
 
Hello All,

I'm trying to find if it's possible to execute multiple commands that use pipes to feed output from one to another in a background. Example:

grep Hello file0 | cut -c10-20 | grep -v bye > file1

Such combinations as :

grep Hello file0 | cut -c10-20 | grep -v bye > file1 &
grep Hello file0 & | cut -c10-20 | grep -v bye > file1

do not seem to work. I'm trying to start multiple processes like this at the same time from the for loop so they will be executed in parallel. Could anyone give me a hint how to achieve this?

Thanks,
PN.

wanderedinn 07-15-2008 08:21 AM

Your first example should work:

grep Hello file0 | cut -c10-20 | grep -v bye > file1 &

It works for me. Check your data and premises of what you expect the output to be. You might consider posting example data so folks can better assist you with debugging this problem.

Your second example will definitely NOT work as the & terminates the command, thus the pipe following it, doesn't have any input going to it.

colucix 07-15-2008 08:29 AM

You can try named pipes. See man mkfifo, Introduction to Named Pipes (an old article from Linux Magazine) and an example on the Advanced Bash Scripting Guide, here.

pn8830 07-15-2008 10:47 AM

Thank you, Everybody for replies!
Honestly I cannot explain why it did not work for me at first but I was able to get what I wanted with bash grouping:

( grep Hello file0 | cut -c10-20 | grep -v bye > file1 ) &

Thanks again,
PN


All times are GMT -5. The time now is 06:31 AM.