Put it all Together

This is just a quick article that may show one of the reasons I write this material. We’re just going to put together a couple of pages from this site in an example of real-world use.

So, if you remember, I told you how to use dpkg to get a list of installed applications. The command I used on that page was:

[code]dpkg -l > Documents/installed_apps.txt[/code]

Well, the output from that is more information than I really need. It looks like this:

[code]ii abiword 3.0.2-6 amd64 efficient, featureful word processor with collaboration
ii abiword-common 3.0.2-6 all efficient, featureful word processor with collaboration — common files
ii accountsservice 0.6.45-1ubuntu1.3 amd64 query and manipulate user account information
ii ack 2.22-1 all grep-like program specifically for large source trees[/code]

That’s plenty informative – but I want just the name of the applications. Sure enough, we can use ‘AWK‘ to do this. 

On that page, we have this command:

[code]awk ‘{ print $2 }’ countries.txt > finished.txt[/code]

So, let’s mix the two together! We can do that!

Let’s see… I’ll obviously need to change the paths and file names. Coincidentally, I’ll not need to change the column (the bit about { print $2 }) because I still want the second column. 

What does it end up looking like?

[code]awk ‘{ print $2 }’ Documents/installed_apps.txt > Documents/InstalledApps.txt[/code]

Now, navigate to your documents folder and open InstalledApps.txt with your favorite text editor. You’ll see that it looks a bit like this:


You’ll still have some unwanted text at the top of the page, but it works well enough to get the job done. It’s reasons like that which motivate me to write this material.