Select record having different value in second column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select record having different value in second column
# 1  
Old 05-17-2012
Select record having different value in second column

I want records which have more than one and different value in the second column on the below sample file.
Ex, I have the samle file below :-
Code:
XYZ 1
XYZ 3
abc 1
abc 1
qwe 2
qwe 1
qwe 3

I want to select XYZ and QWE line only.

Last edited by Scrutinizer; 05-17-2012 at 04:49 AM.. Reason: code tags
# 2  
Old 05-17-2012
Try this...

Code:
SELECT max(rowid) FROM tablename GROUP BY columnname


Last edited by Scrutinizer; 05-17-2012 at 04:49 AM.. Reason: code tags
Mohammed Fareed
# 3  
Old 05-17-2012
I need to do that operation on a file.....Just thinking of any unix command ??
# 4  
Old 05-17-2012
Code:
$ sort -u test.txt | awk '{a[$1]++;next}END{for(i in a){if(a[i]>=2){print i}}}'
XYZ
qwe

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 05-17-2012
what s your condition?
if the columnn2 is higher than two(2) val ?
Code:
# awk '$2>2{print $1}' infile
XYZ
qwe

# 6  
Old 05-17-2012
My condition is that...the coulmn2 should have 2 distinct values atleast....

It could be anything as below...
Code:
1,2
2,3
1,3
1,2,3
2,3,1


Last edited by Scrutinizer; 05-17-2012 at 05:19 AM.. Reason: code tags
# 7  
Old 05-17-2012
Quote:
Originally Posted by Sanjeev Yadav
My condition is that...the coulmn2 should have 2 distinct values atleast....

It could be anything as below...
Code:
1,2
2,3
1,3
1,2,3
2,3,1

maybe try this
Code:
# awk '{x=",";a[$1]=a[$1]&&p!=$2?a[$1]x$2:$2;p=$2}END{for(i in a){if(length(a[i])!=1)print i,a[i]}}' file
XYZ 1,3
qwe 2,1,3

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to select lines with maximum value of each record based on column value

Hello, I want to get the maximum value of each record separated by empty line based on the 3rd column of each row within each record? Input: A1 chr5D 634 7 82 707 A2 chr5D 637 6 82 713 A3 chr5D 637 5 82 713 A4 chr5D 626 1 82 704... (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

3. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

4. Shell Programming and Scripting

select last column

Hi! From a file the format of whichis as in the sample here below, I need to get two files having just 2 columns, being - for the first file - the 2nd than the 1st from the original file; and - for the second file - the LAST then the 1st column of the original file. Moreover, I would sort the... (3 Replies)
Discussion started by: mjomba
3 Replies

5. Shell Programming and Scripting

Select record with MAX value in MySQL

Hi there, I have trouble selecting record that contain one biggest value for a group of other values. I mean, this is my table: mysql> SELECT * FROM b; +----+------+-------+ | id | user | value | +----+------+-------+ | 1 | 1 | 100 | | 3 | 1 | 150 | | 5 | 1 | 300 | | 6... (20 Replies)
Discussion started by: chebarbudo
20 Replies

6. UNIX for Dummies Questions & Answers

to select according to the second column..!!

the input is : 6298 | anna | chennai | 7/4/08 3981 | dastan | bagh | 8/2/07 6187 | galma | london | 9/5/01 3728 | gonna | kol | 8/2/10 3987 | hogja | mumbai | 8/5/09 2898 | homy | pune | 7/4/09 9167 | tamina | ny | 8/3/10 4617 | vazir | ny now how to get the following output : 3987 |... (4 Replies)
Discussion started by: adityamitra
4 Replies

7. Shell Programming and Scripting

How to select and edit on a particular column?

How can I use awk to pick a particular column and work on it? For example, I want to count the number of characters in column10 that are separated by |? Thank you. (2 Replies)
Discussion started by: ivpz
2 Replies

8. Shell Programming and Scripting

select a column

I've a file like this: andrea andre@lol.com october antonio@lol.com marco 45247@pop.com kk@pop.com may pollo@lol.com mary mary@lol.com can I select only the column with email adress? can I utilise a filter with @ ? I want obtain this: ... (2 Replies)
Discussion started by: alfreale
2 Replies

9. Shell Programming and Scripting

Select Record based on First Column

Hi, I have a file with multiple records...and I have to select records based on first column....here is the sample file... I01,abc,125,1a2,LBVI02 I01,abc,126,2b5,LBVI02 I02,20070530,254,abc,LLBI01 I02,20070820,111,bvd,NGBI01 I need all records with I01 in first field in one file and... (8 Replies)
Discussion started by: mgirinath
8 Replies
Login or Register to Ask a Question