LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   wanted awk solution... (https://www.linuxquestions.org/questions/linux-software-2/wanted-awk-solution-709924/)

visitnag 03-07-2009 07:34 PM

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!!

H_TeXMeX_H 03-08-2009 04:29 AM

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

sureshsujatha 03-09-2009 01:46 PM

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!
:)

visitnag 03-14-2009 06:57 AM

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.


All times are GMT -5. The time now is 08:38 PM.