LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 11:42 AM   #1
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 124

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, 11:54 AM   #2
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
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 11:55 AM.
 
Old 05-07-2010, 12:33 PM   #3
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 124

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, 12:49 PM   #4
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
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, 01:19 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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, 01:53 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,013

Rep: Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225Reputation: 1225
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, 01:53 PM   #7
bluethundr
Member
 
Registered: Jun 2003
Location: Summit, NJ
Distribution: CentOS 5.4
Posts: 124

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, 03: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 03:07 PM.
 
Old 05-07-2010, 05:14 PM   #9
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: *buntu, Vector
Posts: 499

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

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

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

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

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

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


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:08 PM
Use a pipe in a cron command? jlinkels Linux - Software 3 01-30-2009 02:57 PM
how to: a pipe command? youngstorm Linux - Newbie 2 02-02-2005 11:52 AM


All times are GMT -5. The time now is 06:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration