LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2003, 12:41 AM   #1
puzz_1
Member
 
Registered: May 2003
Posts: 49

Rep: Reputation: 15
Question chaining multiple commands??


how do you pipe output from one command to another?

something like

which mplayer | rpm -qf

I am trying to find out which rpm mplayer belogns to.....but it doesn't work
neither does

which mplayer | rpm -qf -

help.....
 
Old 05-27-2003, 01:05 AM   #2
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
you can rpm -qa|grep mplayer
 
Old 05-27-2003, 01:06 AM   #3
born4linux
Senior Member
 
Registered: Sep 2002
Location: Philippines
Distribution: Slackware, RHEL&variants, AIX, SuSE
Posts: 1,127

Rep: Reputation: 49
or

rpm -qf $(which mplayer)

if that's what u meant in ur post.
 
Old 05-27-2003, 01:53 AM   #4
puzz_1
Member
 
Registered: May 2003
Posts: 49

Original Poster
Rep: Reputation: 15
Well I know this will work in this case. But I meant it as an example of how to use pipes to chain multiple commands. How do you do it in general though??
 
Old 05-27-2003, 01:55 AM   #5
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 60
screwed up

Last edited by fancypiper; 05-27-2003 at 01:59 AM.
 
Old 05-27-2003, 01:58 AM   #6
fancypiper
LQ Guru
 
Registered: Feb 2003
Location: Sparta, NC USA
Distribution: Ubuntu 10.04
Posts: 5,141

Rep: Reputation: 60
You mean something like this?

<command> | <another command> ; <then do this command> | <yet another command>

or

<command> | <2nd command> | <3rd command> | <4th command>

A good article about it: Linux and the Tools Philosophy

Last edited by fancypiper; 05-27-2003 at 02:13 AM.
 
Old 05-27-2003, 02:07 AM   #7
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
Or do you mean:
<command> | <take output from last command as input for this command> output

Cool
 
Old 05-27-2003, 05:21 AM   #8
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
that rpm -qa|grep mplayer
is a pipe. rpm -qa lists all the packages installed.
here all that text is piped into grep which searches
it for the word mplayer, then when mplayer is found,
grep prints the line that it was found on.

in general a program that can send a stream of
text or bytes is sent to the input of another program
that does something to that data.

tar clfv - .|(cd /mnt/copy; tar xpf -)

another example to look at
 
Old 05-27-2003, 10:57 AM   #9
kkempter
Member
 
Registered: Dec 2002
Posts: 187

Rep: Reputation: 30
Try this :

rpm -q -a | grep mplayer
 
Old 05-27-2003, 11:32 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
seeing as everyone else said exactly the same thing, i might as well

rpm -qa | grep mplayer

it's also wrong... but nevermind. actually answering the question though, a program can only be used with a pipe if that is how it is written. while it could be designed for rpm to accept a file name through a pipe it is not particuarly useful, and so presumably no one bothered implementing it. personally in your example i would have said

rpm -qf `which mplayer`

but obviously that was only used as an example. you've got the right idea, it just isn't possible in that example.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vim: Piping through multiple external commands tragos Linux - Software 2 03-19-2005 01:09 PM
execute multiple ssh remote commands tom221 Linux - Newbie 2 01-28-2005 01:00 PM
executing multiple commands by ssh jpan Linux - General 1 10-22-2004 02:12 PM
Passing multiple commands to SU adamrad Linux - General 2 03-26-2004 10:53 AM
Multiple commands with exec! dtheorem Linux - General 1 03-14-2004 03:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:14 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