I have got a file BeforeSort.txt having 40 fields seperated by "|"
First field= RecordType (Value will be P or FP)
Second field= CamCode
Third field = UpdatingDate
Fourth field = ProductType
Fifth field = ActionCode (Value may be 01, 02 or 03)
Sixth field = ProductCode
and so on
My requirement is that to sort the above file to get unique records based on Second, Fourth and Sixth fields AND also
(1) If there are multiple records for above 3 key fields and with first field RecordType P and FP then take only P record
(2) If there are multiple records for above 3 key fields and with first field RecordType P only then take only P record
(3) If there are multiple records for above 3 key fields and with first field RecordType FP only then take only FP record
I used following sort command to get required records as above :
sort -ur -t "|" -k 2,2 -k 4,4 -k 6,6 BeforeSort.txt > AfterSort.txt
File format (for 4 records) is like below
P|0049|2005-12-18 10:14:37|04|02|R5V2*L503BB6|64BA|BO2A|70|05|3E|70|29|BR:RE BARBARA|GK:MENSI SERGIO|CD00061376||L50303|STD|7051|V2|MULTIWATT 15L SPLIT VERT.|3.25|1F01
3489|0|55|0|E|98|BS05|01|38285|P|15|CZ|CZ||||e3
FP|0049|2005-12-18 10:14:37|04|02|R5V2*L503BB6|64BA|BO2T|70|05|3E|70|29|BR:RE BARBARA|GK:MENSI SERGIO|||L50303|STD||V2|MULTIWATT 15L SPLIT VERT.|||0|55|0|E||BS05||||15
||||||e3
P|0049|2005-12-18 10:13:56|04|02|R8V2*L503BB6|64BA|BO2A|70|05|3E|70|29|BR:RE BARBARA|GK:MENSI SERGIO|CD00061379||L50303|STD|7051|V2|MULTIWATT 15L SPLIT VERT.|3.25|1F01
3339|0|55|0|E|98|BS05|01|38282|P|15|CZ|CZ||||e3
FP|0049|2005-12-18 10:13:56|04|02|R8V2*L503BB6|64BA|BO2T|70|05|3E|70|29|BR:RE BARBARA|GK:MENSI SERGIO|||L50303|STD||V2|MULTIWATT 15L SPLIT VERT.|||0|55|0|E||BS05||||15
||||||e3
This command is working fine for a small file.
==============
Now the actual problem :
But when I executed the above command for a real big file PRinLG90_PFP and redirecting the output in file PRinLG90_PFPSort. Then this output file contains some unexpected record for some of ProductCodes.
(I have attached file PRinLG90_PFP.txt in zip file PRinLG90_PFP.zip)
sort -ur -t "|" -k 2,2 -k 4,4 -k 6,6 PRinLG90_PFP.txt > PRinLG90PFPSort.txt
For Example :
(1) For sixth field ProductCode R5V2*L503BB6 there are two records with first field RecordType = P & FP and fourth field CamCode = 0049 in file PRinLG90_PFP. And in file PRinLG90_PFPSort there is record of first field RecordType = P
(Which is the required and right output record).
(2)But for sixth field ProductCode R8V2*L503BB6 there are two records with first field RecordType = P & FP and fourth field CamCode = 0049 in file PRinLG90_PFP. But in file PRinLG90_PFPSort there is record of first field RecordType = FP
(While our requirement is that ,it should be P record instead of FP record)
I could not understand the above different behaviour of this used sort command.
could I take your expert help on this to know the reason/action of this uncertain behaviour of this above sort command or if there is any other alternate to fulfill my requirement.
Please help me, because this command is to be used to send a very important and urget delivery
Many Thanks & Regards,
Pankaj Rai