Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is fragment of my input:

DGD3 SOL10
DGD53 SOL15
DGD100 SOL15
DGD92 SOL20
DGD41 SOL22
DGD62 SOL35
DGD13 SOL40
DGD13 SOL40

My expected output

DGD53 SOL15
DGD100 SOL15
DGD13 SOL40
DGD13 SOL40

In my data I have sometimes SOL duplicates (not more than two repetitions not for example three times some SOL in a file but only duplicates). SOL is in my second column ($2). So I need a program which print whole line (DGD and SOL) when I find duplicate SOL ($2). Could you help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
197 views
Welcome To Ask or Share your Answers For Others

1 Answer

Adding one more way in awkish style, where to get all value count in first read of Input_file and print all values as per their count in 2nd read. Fair warning this may not be fast as other 2 solutions but should be simple from understanding purposes.

awk '
FNR==NR{
  count[$2]++
  next
}
(count[$2]>1)
' Input_file  Input_file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...