Extracting columns

The output of the below command is :
[root@wiki ~]# yum -e0 -d0 check-update

dnsmasq.i386 2.45-1.1.el5_3 updates
ecryptfs-utils.i386 75-5.el5 updates
fetchmail.i386 6.3.6-1.1.el5_3.1 updates
firefox.i386 3.0.14-1.el5.centos updates
gdm.i386 1:2.16.0-56.el5.centos updates
gnutls.i386 1.4.1-3.el5_3.5 updates
lftp.i386 3.7.11-4.el5 updates
mysql.i386 5.0.77-3.el5 updates
mysql-devel.i386 5.0.77-3.el5 updates
mysql-server.i386 5.0.77-3.el5 updates
nfs-utils.i386 1:1.0.9-42.el5 updates
nspr.i386 4.7.5-1.el5_4 updates
nspr-devel.i386 4.7.5-1.el5_4 updates
openssh.i386 4.3p2-36.el5 updates
openssh-askpass.i386 4.3p2-36.el5 updates
openssh-clients.i386 4.3p2-36.el5 updates
openssh-server.i386 4.3p2-36.el5 updates
openssl.i686 0.9.8e-12.el5 updates
openssl-devel.i386 0.9.8e-12.el5 updates
xulrunner.i386 1.9.0.14-1.el5_4 updates

I am using the following command for extracting the first two columns:
yum -e0 -d0 check-update|awk '{print $1,$2}'

That gives me the following output:
dnsmasq.i386 2.45-1.1.el5_3
ecryptfs-utils.i386 75-5.el5
fetchmail.i386 6.3.6-1.1.el5_3.1
firefox.i386 3.0.14-1.el5.centos
gdm.i386 1:2.16.0-56.el5.centos
gnutls.i386 1.4.1-3.el5_3.5
lftp.i386 3.7.11-4.el5
mysql.i386 5.0.77-3.el5
mysql-devel.i386 5.0.77-3.el5
mysql-server.i386 5.0.77-3.el5
nfs-utils.i386 1:1.0.9-42.el5
nspr.i386 4.7.5-1.el5_4
nspr-devel.i386 4.7.5-1.el5_4
openssh.i386 4.3p2-36.el5
openssh-askpass.i386 4.3p2-36.el5
openssh-clients.i386 4.3p2-36.el5
openssh-server.i386 4.3p2-36.el5
openssl.i686 0.9.8e-12.el5
openssl-devel.i386 0.9.8e-12.el5
xulrunner.i386 1.9.0.14-1.el5_4

I want to extract the first two columns as produced by by the command:
yum -e0 -d0 check-update
and not with the space truncated between the 1st and 2nd column.

Plz help

If I understood correctly, you just wanna get'rid of the space between both fields, this should do the trick:

yum -e0 -d0 check-update | awk '{print $1""$2}'

Just remove the comma from between the two fields printed: -

yum -e0 -d0 check-update | nawk ' {print $1$2 } '

nawk is absent in my system

---------- Post updated at 05:09 PM ---------- Previous update was at 04:46 PM ----------

Can anyone help

yum -e0 -d0 check-update | awk '{print $1" "$2}'

or

yum -e0 -d0 check-update | cut -d' ' -f1-2

Dude, did you try my awk suggestion or the folks below?

works with awk as well as nawk.

What OS are you using?

Hi, Perhaps it is good to note that the OP does seem to want a space between the two fields.

Hi guys,

Sorry for the late reply,was a bit busy with certain things...

No the commands didn't give me the expected results. I am using centos 5.3. I am using putty to login to the remote server.
Still i am not getting the first two columns in exactly the same format as given by the command: yum -e0 -d0 check-update

OK, I see, you would like to keep the exact same spacing that yum spits out. In that case we should cut of everything after the second field, e.g. like so:

yum -e0 -d0 check-update | sed 's/[\t ]*[^\t ]*$//'

But even after using the recommended command i am getting the same three columns as output, while i want the first two columns in the same format.

yum -e0 -d0 check-update| gawk '{print $1 $2}'

I have already tried the command earlier but to no avail. The output that i am getting is:

dnsmasq.i3862.45-1.1.el5_3
ecryptfs-utils.i38675-5.el5
fetchmail.i3866.3.6-1.1.el5_3.1
firefox.i3863.0.14-1.el5.centos
gdm.i3861:2.16.0-56.el5.centos
gnutls.i3861.4.1-3.el5_3.5
lftp.i3863.7.11-4.el5
mysql.i3865.0.77-3.el5
mysql-devel.i3865.0.77-3.el5
mysql-server.i3865.0.77-3.el5
nfs-utils.i3861:1.0.9-42.el5
nspr.i3864.7.5-1.el5_4
nspr-devel.i3864.7.5-1.el5_4
openssh.i3864.3p2-36.el5
openssh-askpass.i3864.3p2-36.el5
openssh-clients.i3864.3p2-36.el5
openssh-server.i3864.3p2-36.el5
openssl.i6860.9.8e-12.el5
openssl-devel.i3860.9.8e-12.el5
xulrunner.i3861.9.0.14-1.el5_4

Plz consult the attached picture. I want the output in exactly the same format(without the blue background)

:eek: You can learn howto use

 tags when you post code sample or required output.

To keep the forums high quality for all users, please take the time to format your posts correctly.
[*]Use Code Tags when you post any code or data samples so others can easily read your code. 
You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags  and  by hand.)

[*]Avoid adding color or different fonts and font size to your posts. 
Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

[*]Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

---------- Post updated at 11:13 AM ---------- Previous update was at 11:11 AM ----------

# awk '{printf "%-40s%s\n",$1,$2}' file
dnsmasq.i386                            2.45-1.1.el5_3
ecryptfs-utils.i386                     75-5.el5
fetchmail.i386                          6.3.6-1.1.el5_3.1
firefox.i386                            3.0.14-1.el5.centos
gdm.i386                                1:2.16.0-56.el5.centos
gnutls.i386                             1.4.1-3.el5_3.5
lftp.i386                               3.7.11-4.el5
mysql.i386                              5.0.77-3.el5
mysql-devel.i386                        5.0.77-3.el5
mysql-server.i386                       5.0.77-3.el5
nfs-utils.i386                          1:1.0.9-42.el5
nspr.i386                               4.7.5-1.el5_4
nspr-devel.i386                         4.7.5-1.el5_4
openssh.i386                            4.3p2-36.el5
openssh-askpass.i386                    4.3p2-36.el5
openssh-clients.i386                    4.3p2-36.el5
openssh-server.i386                     4.3p2-36.el5
openssl.i686                            0.9.8e-12.el5
openssl-devel.i386                      0.9.8e-12.el5
xulrunner.i386                          1.9.0.14-1.el5_4
yum -e0 -d0 check-update | awk '{printf "%-40s%s\n",$1,$2}'

---------- Post updated at 10:24 AM ---------- Previous update was at 10:22 AM ----------

Worked like a charm. Explanation of the syntax will be highly appreciated.
Thanks

  1. You didn't use the [code] tags to preserve the text format and that create the confusion.
  2. You already have the solution from the beginning, the only difference is the print format using printf, google or search this forum for example.