Visit Our UNIX and Linux User Community


Extracting columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting columns
# 1  
Old 10-06-2009
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
# 2  
Old 10-06-2009
Quote:
Originally Posted by proactiveaditya
The output of the below command is :

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}'
# 3  
Old 10-06-2009
Just remove the comma from between the two fields printed: -

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

# 4  
Old 10-06-2009
nawk not installed

nawk is absent in my system

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

Can anyone help
# 5  
Old 10-06-2009
Code:
yum -e0 -d0 check-update | awk '{print $1" "$2}'

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

# 6  
Old 10-07-2009
Quote:
Originally Posted by proactiveaditya
nawk is absent in my system

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

Can anyone help
Dude, did you try my awk suggestion or the folks below?
# 7  
Old 10-07-2009
works with awk as well as nawk.

What OS are you using?

Previous Thread | Next Thread
Test Your Knowledge in Computers #961
Difficulty: Medium
SQL MammyJammer was a computer worm that caused a denial of service on some Internet hosts and dramatically slowed down general Internet traffic in 2003.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting multiple columns with awk

Hi everyone!! I need to apply a simple command to extract columns from a matrix, but I need to extract contemporary from the first to the tenth columns, than from the eleventh to the twentyth and so on... how can i do that? (1 Reply)
Discussion started by: gabrysfe
1 Replies

2. Shell Programming and Scripting

Extracting wanted columns

Suppose file1 1 3 8 9 file2 1 2 3 4 5 6 7 8 9 10 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 I want to print columns listed in file 1 from file2. so the output will look like 1 3 8 9 1 1 0 1 (3 Replies)
Discussion started by: johnkim0806
3 Replies

3. UNIX Desktop Questions & Answers

Extracting only unique data between two columns

:wall:Hi there, I am trying to extract/filter a unique data between specific columns from a tab deliminated file, that has a number of columns: input file as follow: 5 rs1 70 A C 7 1 1 Blue 5 rs9 66 A E ... (2 Replies)
Discussion started by: houkto
2 Replies

4. Shell Programming and Scripting

Using columns from 2 files and extracting string

Hi All, I have 2 files with a common column. File 1 looks like NAME START POS1 POS2 N1 1234 1236 1237 N2 1245 1248 1250 .. .. File 2 looks like NAME STRING N1 ABCDEFGH N2 EFGHBCD N3 PQRSSTUV .. ...... ... (25 Replies)
Discussion started by: alpesh
25 Replies

5. Shell Programming and Scripting

extracting columns from 2 files

Hello, I have 2 files file1 & file2 = a1 b1 a2 b2 a3 b3 ... = c1 d1 c2 d2 c3 d3 ... I need to compare if b(i)=c(j) . i,j=1,2,3,4,... If yes, right a(i) d(j) in output file3 per line (1 Reply)
Discussion started by: newpromo
1 Replies

6. Shell Programming and Scripting

Extracting only a few columns!!!?

Hi All, I have a text file which looks like below. ################################################ Name:xxxxxxx Version:1.0 Class: 2 City : Bangalore Component Part Action Nb New Part Naming Part Name 12345 default 12345.12345 Bad 23456 ... (6 Replies)
Discussion started by: smarty86
6 Replies

7. Shell Programming and Scripting

extracting columns with awk

Friends, I have a file with fileds in the following order sda 4.80 114.12 128.69 978424 1103384 sdb 0.03 0.40 0.00 3431 0 sda 1.00 0.00 88.00 0 176 sdb ... (14 Replies)
Discussion started by: achak01
14 Replies

8. Shell Programming and Scripting

extracting multiple consecutive columns using awk

Hello, I have a matrix 200*10,000 and I need to extract the columns between 40 and 77. I dont want to write in awk all the columns. eg: awk '{print $40, $41, $42,$43 ... $77}'. I think should exist a better way to do this. (10 Replies)
Discussion started by: auratus42
10 Replies

9. Shell Programming and Scripting

Need help in extracting columns

Hi , I have a file having around 8 columns spereated by space . Now that I need to extract columns from this. The problem is this functionality is needed in a script and the required columns are dynamic and can range from 2 columns to 8 columns at a time . What I tried without luck is ... (6 Replies)
Discussion started by: praveenbvarrier
6 Replies

10. UNIX for Dummies Questions & Answers

Extracting columns from different files for later merging

Hello! I wan't to extract columns from two files and later combine them for plotting with gnuplot. If the files file1 and file2 look like: fiile1: a, 0.62,x b, 0.61,x file2: a, 0.43,x b, 0,49,x The desired output is a 0.62 0.62 b 0.61 0.49 Thank you in advance! (2 Replies)
Discussion started by: kingkong
2 Replies

Featured Tech Videos