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 10:57 PM
awk and sed filtering invinzin21 Shell Programming and Scripting 2 01-11-2008 03:56 AM
awk filtering ? varungupta UNIX for Advanced & Expert Users 4 09-17-2007 03:55 AM
Filtering Data Raynon Shell Programming and Scripting 7 09-05-2007 07:38 PM
Filtering out data ... videsh77 UNIX for Dummies Questions & Answers 1 12-29-2004 04:59 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-19-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
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!
  #2 (permalink)  
Old 09-19-2007
ajcannon ajcannon is offline
Registered User
  
 

Join Date: Aug 2007
Location: Binfield, Berkshire. UK
Posts: 91
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?
  #3 (permalink)  
Old 09-19-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0