LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-07-2009, 08:34 PM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
wanted awk solution...


A typical problem frm me....I have a file like the following....

49998784|01|200901|41
49998784|01|200901|33
49998784|01|200901|33
49998784|01|200812|33
49998763|01|200901|33
49998763|01|200812|33
49998750|01|200812|33
49998750|01|200811|33
49998743|01|200812|33
49998743|01|200811|33
49998741|01|200902|41
49998741|01|200902|33
49998741|01|200902|33
49998741|01|200901|33
49998741|01|200901|41
49998733|01|200901|33
49998733|01|200812|33

The file has a "|" as the field separator. The first field is policy
number, second one is mode,third one is due paid,fourth ono is stat.

1. if the first and third fields are same with the next record
corresponding fileds, and fourth field is not same with the next
record corresponding field skip these two records.

2. next, if the first and fourth fields are same, then select the
record which is having a latest due(third field) and skip the other similar records and pickup next record.

The out put of the above should come like this.

49998784|01|200901|33
49998763|01|200901|33
49998750|01|200812|33
49998743|01|200812|33
49998741|01|200902|33
49998733|01|200901|33

Thank you!!
 
Old 03-08-2009, 05:29 AM   #2
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Right, and you expect us to write this script for you from scratch ? I think you should at least take a stab at it first.

For the field separator, use

Code:
awk -F'|'
or
awk -F\|
Then just write some if statements for all the conditions you stated in that order, knowing that field 1 is $1, field 2 is $2, etc.

See here for more help:
http://www.grymoire.com/Unix/Awk.html
 
Old 03-09-2009, 02:46 PM   #3
sureshsujatha
Member
 
Registered: Mar 2009
Posts: 40

Rep: Reputation: 15
Cool

Since you seem to want to write some sort of a programming logic which decides what content is filtered out and what's not - Ideally - I'd suggest writing an application in java that'll do the trick for you.

Let me know if you'd be interested in that .... I could cook up something that you can use!

Last edited by sureshsujatha; 03-14-2009 at 01:14 AM.
 
Old 03-14-2009, 07:57 AM   #4
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Hi sujatha,

I could solve the problem using awk but itsbit lengthy...Could you please give java solution? I work on Ubuntu8.1 and RHEL4 also. It would be great help for me(of course i am new to java, but i want to see the code)

Thanks in advance.

By the by I am from India and working for an Insurance Company in Hyd.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed, awk - solution for filtering logs cmeyer Linux - Software 8 10-11-2008 02:01 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
Why use an enterprise software solution vesus a diy (home made) solution checkmate3001 Linux - Server 1 12-16-2007 03:24 PM
Backup solution wanted badly thejasondean Linux - Software 6 01-12-2007 08:16 AM
Recommendation for WLAN Solution wanted!!! Fredy71 Linux - Hardware 9 09-01-2006 09:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration