The UNIX and Linux Forums  

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


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
filtering the logs prvnrk Shell Programming and Scripting 5 04-08-2008 06:57 PM
awk and sed filtering invinzin21 Shell Programming and Scripting 2 01-10-2008 11:56 PM
awk filtering ? varungupta UNIX for Advanced & Expert Users 4 09-16-2007 11:55 PM
Filtering Data Raynon Shell Programming and Scripting 7 09-05-2007 03:38 PM
Filtering out data ... videsh77 UNIX for Dummies Questions & Answers 1 12-29-2004 12:59 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-2007
Registered User
 

Join Date: Jan 2006
Posts: 145
Stumble this Post!
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
Forum Sponsor
  #2 (permalink)  
Old 09-19-2007
Registered User
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
Stumble this Post!
More Info

It is good that you have supplied 'in' file format and wanted/desired 'out' format but it will help if you can tell us what the actual need is.

What is the algorithm/method you want to apply to the input to generate the output - it is not too clear from your examples. I am guessing you want to get entries from aaa until aaa is repeated. Is this the case?
Reply With Quote
  #3 (permalink)  
Old 09-19-2007
Registered User
 

Join Date: Jan 2006
Posts: 145
Stumble this Post!
Unhappy

The requests are:

the program will go line #1; it will compare this line #1 to every line in the file; and if column #2 is not match AND column #3 is match to the next lines, then print all the lines those meet the condition. The program will go to line #2 and repeat the process til the end of the file.

I am not sure this is clear enough. Please let me know.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0