LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-15-2008, 07:49 AM   #1
pn8830
LQ Newbie
 
Registered: May 2006
Location: NJ, USA
Distribution: Slackware 10.1
Posts: 2

Rep: Reputation: 0
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.
 
Old 07-15-2008, 08:21 AM   #2
wanderedinn
LQ Newbie
 
Registered: Jun 2005
Location: Georgia USA
Distribution: Mandriva powerpack 2009, Red Hat Enterprise Linux 5.4
Posts: 5

Rep: Reputation: 0
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.
 
Old 07-15-2008, 08:29 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 07-15-2008, 10:47 AM   #4
pn8830
LQ Newbie
 
Registered: May 2006
Location: NJ, USA
Distribution: Slackware 10.1
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Background job won't stay in the background! JMJ_coder Linux - General 1 03-17-2008 06:05 PM
Change background in solaris and Xterm background also EvilAngel Solaris / OpenSolaris 2 01-31-2005 11:25 AM
Background and Xterm transparent background EvilAngel Linux - General 1 01-31-2005 09:40 AM
In KDE, aterm uses GNOME background rather than KDE background for transparent backgr cpbl Linux - Software 4 01-01-2005 10:26 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 12:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration