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. |
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. |
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.
|
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. |