If there are duplicates in the file, the first record should go to valid file and remaining duplicate records should be moved to invalid file using a PIG script.
Below is the scenario.
Input:
Acc|Phone|Name
1234|333-444-5555|XYZ
4567|222-555-1111|ABC
1234|234-123-0000|DEF
9999|123-456-1890|PQR
8734|456-879-1234|QWE
4567|369-258-0147|NNN
1234|987-654-3210|BLS
output: Two files
1. Valid rec:
1234|333-444-5555|XYZ
4567|222-555-1111|ABC
9999|123-456-1890|PQR
8734|456-879-1234|QWE
2. Invalid rec:
1234|234-123-0000|DEF
4567|369-258-0147|NNN
1234|987-654-3210|BLS
Invalid records are not necessarily to be in same order. It can also be like this.
Invalid rec:
1234|234-123-0000|DEF
1234|987-654-3210|BLS
4567|369-258-0147|NNN
Scenario 2: Input:
1234|333-444-5555|XYZ
4567|222-555-1111|ABC
1234|234-123-0000|DEF
9999|123-456-1890|PQR
8734|456-879-1234|QWE
4567|369-258-0147|NNN
1234|087-654-3210|BLS
1234|303-444-5555|XYZ
4567|122-555-1111|ABC
1234|134-123-0000|DEF
9999|123-456-1890|PQR
8734|456-879-1234|QWE
4567|069-258-0147|NNN
1234|086-654-3210|BLS
1234|033-444-5555|XYZ
4567|200-555-1111|ABC
1234|230-123-0000|DEF
9999|023-456-1890|PQR
8734|456-779-1234|QWE
4567|309-258-0147|NNN
1234|007-654-3210|BLS
Good Rec:
1234|333-444-5555|XYZ
4567|222-555-1111|ABC
9999|123-456-1890|PQR
8734|456-879-1234|QWE
Can anyone please suggest some idea. I'm only able to get the first record.
Thanks.