-2

This question already has an answer here:

Input:

1,1,10,1
2,1,10,3
3,0,10,1

Expected Output:

1,1,10,1
2,1,10,3

So how to print lines if field number 2 and 3 repeated in another line.

marked as duplicate by Sundeep, msp9011, Isaac, slm Aug 23 '18 at 21:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Will those be adjacent lines, or scattered all over the place? – RudiC Aug 23 '18 at 16:24
1

Quick'n'dirty method (requiring two passes over the file, the first to count occurrences of $2,$3, and the second to print whenever the field combination is non-unique):

$ awk -F, 'NR==FNR{a[$2 FS $3]++; next} a[$2 FS $3] > 1' file file
1,1,10,1
2,1,10,3
  • the only bad thing it's not showing the duplicate lines under together on big file. but it's did the job ! can i sort based on second and third field to appear under together? – αԋɱҽԃ αмєяιcαη Aug 23 '18 at 15:41
  • I've done it by adding sort -t, -k2 . thanks a lot. – αԋɱҽԃ αмєяιcαη Aug 23 '18 at 15:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.