2

I've been reading about similar question here, however the answer was provided without line number.

[root@test ~]# cat -n file 
     1  123 
     2  123 
     3  234 
     4  234 
     5  123 
     6  345
[root@test ~]#

[root@test ~]# sort file | uniq -c
      3 123 
      2 234 
      1 345
[root@test ~]# 

What I'm looking for is something like this, but in Linux shell script (preferable), or any other scripting solutions.

Output provided by textmechanic.com

( 2 dupe of 1 ): 123 
( 4 dupe of 3 ): 234 
( 5 dupe of 1 ): 123 

1 Answer 1

2

You may use awk:

awk '{if ($1 in a) printf "( %d dupe of %d ): %s\n", NR, a[$1], $1; else a[$1] = NR}' file

( 2 dupe of 1 ): 123
( 4 dupe of 3 ): 234
( 5 dupe of 1 ): 123
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.