Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rearranging file into three columns

Tags:

bash

awk

I am trying to compare the list of installed packages on a couple of computers running CentOS 6.4. The output of yum list installed is not ordered nicely into three columns, e.g.:

ImageMagick.x86_64      6.5.4.7-6.el6_2 @base     
MAKEDEV.x86_64          3.24-6.el6      @anaconda-CentOS-201303020151.x86_64/6.4
ModemManager.x86_64     0.4.0-3.git20100628.el6
                                        @anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager.x86_64   1:0.8.1-43.el6  @anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager-glib.x86_64
                        1:0.8.1-43.el6  @anaconda-CentOS-201303020151.x86_64/6.4

Long lines are wrapped to fit into 80 columns, which means that if I sort this file the information for some packages will be scrambled.. Is there a simple awk command to take this output and print three fields per line?

I have tried searching for similar examples, but I only find cases where people split one long line into columns.

like image 325
andyras Avatar asked Sep 23 '13 16:09

andyras


1 Answers

If each column is guaranteed not to contain spaces then this approach might do the trick:

$ yum list installed | xargs -n3 | column -t
ImageMagick.x86_64          6.5.4.7-6.el6_2          @base
MAKEDEV.x86_64              3.24-6.el6               @anaconda-CentOS-201303020151.x86_64/6.4
ModemManager.x86_64         0.4.0-3.git20100628.el6  @anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager.x86_64       1:0.8.1-43.el6           @anaconda-CentOS-201303020151.x86_64/6.4
NetworkManager-glib.x86_64  1:0.8.1-43.el6           @anaconda-CentOS-201303020151.x86_64/6.4
like image 81
Chris Seymour Avatar answered Nov 12 '22 21:11

Chris Seymour