LinuxQuestions.org
Help answer threads with 0 replies.
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 05-07-2010, 10:42 AM   #1
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 144

Rep: Reputation: 15
Post a (potentially useful) command pipe


I'm trying to get a little better at piping together unix commands.

Here's one that I thought might be useful if I could actually get it working!

Code:
dpkg -l | grep cups |  awk '{print $2}' > foo | aptitude purge < foo
any thoughts?
 
Old 05-07-2010, 10:54 AM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
You might try using the back quote instead (on the ~ key). This will execute cat foo, which should be whatever text is in the file foo.
Code:
dpkg -l | grep cups |  awk '{print $2}' > foo | aptitude purge `cat foo`

Last edited by pljvaldez; 05-07-2010 at 10:55 AM.
 
Old 05-07-2010, 11:33 AM   #3
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 144

Original Poster
Rep: Reputation: 15
hmmm.. I grok... but the above seems to cause an infinite loop! So I suppose I would have to write a small script that would feed apt-get the correct number of 'yeses' to get the job done...
 
Old 05-07-2010, 11:49 AM   #4
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
I think there's a -y switch in aptitude that will assume yes. Can you post your file "foo" just so I can see what's in it (I'm assuming it's a bunch of package names, but I'm not in front of my Lenny box to test it).
 
Old 05-07-2010, 12:19 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Am I understanding that is just to see how to play with pipes and redirection?
As obviously this could have all been much shorter.
 
Old 05-07-2010, 12:53 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
You can't write to and read from a file in a single pipeline: all the programs run in parallel so the contents of the file will not be deterministic.
 
Old 05-07-2010, 12:53 PM   #7
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 144

Original Poster
Rep: Reputation: 15
Thumbs up that did it!!!

Quote:
Originally Posted by bluethundr View Post
hmmm.. I grok... but the above seems to cause an infinite loop! So I suppose I would have to write a small script that would feed apt-get the correct number of 'yeses' to get the job done...
yes, reminding me of the use of back ticks and clueing me on the use of the -y switch was the magic answer!

Code:
dpkg -l | grep cups | awk '{print $2}' > foo | aptitude purge -y `cat foo`
And to answer your question.. yes 'foo' was just a list of package names..

thanks for playing!
 
Old 05-07-2010, 02:05 PM   #8
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Here's my favorite:

In a terminal, say inside X, do:
Code:
$ cat > pipe0
load of
bollocks<return>
Now, *in another terminal*, say outside X, do:
Code:
$ cat < pipe0
Neat eh? And it allows you to paste between X and the black screen.

Close the thing in the first terminal with ctrl+d, end of file. Sorry should have said pipe0 is a 'named pipe'; use mkfifo pipe0 to make it??

Last edited by lugoteehalt; 05-07-2010 at 02:07 PM.
 
Old 05-07-2010, 04:14 PM   #9
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
Can't you just do

Code:
dpkg -l | grep cups |  awk '{print $2}' | aptitude purge -
 
Old 05-07-2010, 05:28 PM   #10
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
I guess you could also do
Code:
aptitude purge -y `dpkg -l | grep cups |  awk '{print $2}'`
 
Old 05-07-2010, 11:48 PM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Code:
aptitude purge -y `dpkg -l | awk '/cups/{print $2}'`
 
Old 05-08-2010, 11:12 AM   #12
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Code:
dpkg-query -f '${Package}\n' -W '*cups*' | aptitude purge -y -

Last edited by ntubski; 05-08-2010 at 11:13 AM. Reason: forgot -y
 
  


Reply

Tags
bash



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
Pipe command shorte85 Linux - Newbie 9 03-13-2009 06:08 PM
Use a pipe in a cron command? jlinkels Linux - Software 3 01-30-2009 01:57 PM
how to: a pipe command? youngstorm Linux - Newbie 2 02-02-2005 10:52 AM

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

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