duplicate values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting duplicate values
# 1  
Old 10-16-2012
duplicate values

Hi,

How to enumerate duplicate values, without sorting the file.

example

1 1
2 1
3 1
1 2
2 2
3 2
1 3
2 3
3 3

Where the first column have the repetead values without sorting,

I would like to get the value of the times that the value is repetead , as I show in the 2 column

Thanks in advance.
# 2  
Old 10-16-2012
I presume the input file only has one column? Try:
Code:
awk '{print $1, ++C[$1]}' file

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 10-16-2012
Thanks for your help, yes the file has only one column,,
I have try the code , but looks like there is a syntax error.. Please advise

---------- Post updated at 03:26 AM ---------- Previous update was at 03:22 AM ----------

Sorry was my mistake,, The code works fine... Thanks again
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find lines with duplicate values in a particular column

I have a file with 5 columns. I want to pull out all records where the value in column 4 is not unique. For example in the sample below, I would want it to print out all lines except for the last two. 40991764 2419 724 47182 Cand A 40992936 3591 724 47182 Cand B 40993016 3671 724 47182 Cand C... (5 Replies)
Discussion started by: kaktus
5 Replies

2. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

3. Shell Programming and Scripting

Remove duplicate values in a column(not in the file)

Hi Gurus, I have a file(weblog) as below abc|xyz|123|agentcode=sample code abcdeeess,agentcode=sample code abcdeeess,agentcode=sample code abcdeeess|agentadd=abcd stereet 23343,agentadd=abcd stereet 23343 sss|wwq|999|agentcode=sample1 code wqwdeeess,gentcode=sample1 code... (4 Replies)
Discussion started by: ratheeshjulk
4 Replies

4. Shell Programming and Scripting

Average values of duplicate rows

I have this file input.txt. I want to take average column-wise for the rows having duplicate gene names. Gene Sample_1 Sample_2 Sample_3 gene_A 2 4 5 gene_B 1 2 3 gene_A 0 5 7 gene_B 4 5 6 gene_A 11 12 13 gene_C 2 3 4 Desired output: gene_A 4.3 7 8.3 gene_B 2.5 3.5 4.5 gene_C 2 3 4... (6 Replies)
Discussion started by: Sanchari
6 Replies

5. Shell Programming and Scripting

Remove duplicate values with condition

Hi Gents, Please can you help me to get the desired output . In the first column I have some duplicate records, The condition is that all need to reject the duplicate record keeping the last occurrence. But the condition is. If the last occurrence is equal to value 14 or 98 in column 3 and... (2 Replies)
Discussion started by: jiam912
2 Replies

6. Shell Programming and Scripting

Append values of duplicate entries

My input file is: LOC_Os01g01870 GO:0006139 LOC_Os01g01870 GO:0009058 LOC_Os01g02570 GO:0006464 LOC_Os01g02570 GO:0009987 LOC_Os01g02570 GO:0008152 LOC_Os01g04380 GO:0006950 LOC_Os01g04380 GO:0009628 I want to append the duplicate values in a tab/space... (2 Replies)
Discussion started by: Sanchari
2 Replies

7. Shell Programming and Scripting

Duplicate values merge

Dear Gents, Please can you help me to solve this problem. Input file... 22057485 ,219 ,1050 22057485 ,223 ,1050 21897425 ,278 ,1050 21897425 ,279 ,1050 21897425 ,287 ,1050 20497465 ,602 ,1051 20517500 ,677 ,1051 20517500 ,681 ,1051 20577555 ,775 ,1052 20577555 ,778... (7 Replies)
Discussion started by: jiam912
7 Replies

8. Shell Programming and Scripting

Extract values of duplicate keys

I have two questions that are related, so it would be great if you can help me with both! Question1: I have a file A that looks like this: a x b y b z c w I want to get something like: a x b y; z c w Given that a,b,c has no spaces. But the other letters might contain spaces. ... (2 Replies)
Discussion started by: Viernes
2 Replies

9. Shell Programming and Scripting

Replace duplicate columns with values from first occurrence

I've a text file with below values viz. multiple rows with same values in column 3, 4 and 5, which need to be considered as duplicates. For all such cases, the rows from second occurrence onwards should be modified in a way that their values in first two columns are replaced with values as in first... (4 Replies)
Discussion started by: asyed
4 Replies

10. Shell Programming and Scripting

Cleaning up Arrays with duplicate values

Hey Gang! So I have two Arrays. @linecount and @hit. Now these arrays contain numbers which I'm using as line placeholders on files. I need these two arrays to sync up and not repeat a number. Here are the contents (spam alert) @linecount 1 28 53 86 87 88 89 90 91 92 93 94 (5 Replies)
Discussion started by: adelsin
5 Replies
Login or Register to Ask a Question