The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



Thread: Filtering Data
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 09-19-2007
bobo bobo is offline
Registered User
 

Join Date: Jan 2006
Posts: 145
Unhappy Filtering Data

file1 contain: (this just a small sample of data it may have thousand of lines)

1 aaa 1/01/1975 delhi
2 bbb 2/03/1977 mumbai
3 ccc 1/01/1975 mumbai
4 ddd 2/03/1977 chennai
5 aaa 1/01/1975 kolkatta
6 bbb 2/03/1977 bangalore

program:

nawk '{
idx= $2 SUBSEP $3
arr[idx] = (idx in arr) ? arr[idx] ORS $0 : $0
arrCnt[idx]++
}
END {
for (i in arr)
if (arrCnt[i] > 1) print arr[i]
}' file1

Result:

2 bbb 2/03/1977 mumbai
6 bbb 2/03/1977 bangalore
1 aaa 1/01/1975 delhi
5 aaa 1/01/1975 kolkatta

Questions:

How the code should be if I need the data result to be like this :


1 aaa 1/01/1975 delhi
3 ccc 1/01/1975 mumbai
2 bbb 2/03/1977 mumbai
4 ddd 2/03/1977 chennai

Please help! Thank you friends!
Reply With Quote
Remove advertisements
!!
!! Forum Sponsor