LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 12-29-2012, 07:15 AM   #1
lingh
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Rep: Reputation: Disabled
Can I pipe this?


I am going to be reinstalling my linux installation and I want to make sure I have installed everything that is currently on my current installation.

I know that

Code:
sudo dpkg -l
Will list all the packages on your system and I have piped it through awk in this way:

Code:
sudo dpkg -l | awk '{ print $2 }'
And that gives me a list of all the packages in a long list, which is fine, but I would like to make this list into one long line, e.g. instead of

package
package
package
package
...

I have

package package package package...

Is this possible? I was thinking that maybe I need to pipe it through sed as well, something like:

Code:
dpkg | awk | sed
But I cannot seem to figure out the logic on the sed part.
 
Old 12-29-2012, 07:23 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,159

Rep: Reputation: 258Reputation: 258Reputation: 258
Hi

You can also tell awk to use a space instead of a newline as separator.

Code:
sudo dpkg -l | awk 'BEGIN {ORS=" "} { print $2 }'
ORS means output record separator.
 
1 members found this post helpful.
Old 12-29-2012, 07:40 AM   #3
lingh
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
That worked perfectly. Thank you
 
Old 12-29-2012, 07:46 AM   #4
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,142

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
you can also try: awk ' { printf " " $2 } '
and remember, you do not need to (must not) use sudo before dpkg:
Code:
dpkg -l | awk ' { printf " " $2 } '
 
Old 12-29-2012, 07:49 AM   #5
lingh
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Why is that? (the sudo dpkg thing) I cannot use su without enabling the root user since I run an Ubuntu system, so the only way to use root tools like dpkg is to use sudo.
 
Old 12-29-2012, 08:02 AM   #6
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,142

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
in general dpkg is used to modify the system, it requires root privileges, so usually you use sudo dpkg <something>. But in your case dpkg -l will not modify the system, just read some info, therefore you not need root access to execute it. In general it is not a good practice (work as root if not really required).
Furthermore you need to type more, sudo will fork an additional process, will use some resources unnecessarily, will slow down the execution and potentially unsafe.
 
1 members found this post helpful.
Old 12-29-2012, 08:05 AM   #7
lingh
LQ Newbie
 
Registered: Oct 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Oh I understand, I need to use sudo with dpkg when I am going to make a change such as installing packages. But dpkg -l does not make any changes, so using sudo is redundant for that operation. I see now. Thanks again
 
  


Reply


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
PHP shell_exec() always gives error "Broken pipe" when using pipe burek Linux - Server 1 01-19-2012 07:04 AM
[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe? zyroot998 Programming 5 03-03-2011 09:10 PM


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