Duplicate removal


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Duplicate removal
# 1  
Old 05-13-2013
Duplicate removal

I have an input file of 5GB which contains duplicate records and have to remove duplicate records by retaing first instance of that record .

Based on 5 fields the duplicates has to be removed .

Kindly request to help me in writing a Unix Script.




Thanks
Asim
# 2  
Old 05-13-2013
try

Code:
awk '!A[$0]++' file

# 3  
Old 05-13-2013
Quote:
Originally Posted by duplicate
Based on 5 fields the duplicates has to be removed .
What are the 5 fields and what's the field seperator?
# 4  
Old 05-13-2013
Its a positional file based on the field position it has to track the field


5 fields are FirstName ,LastName,DOB,ZipCode,IdentificationID.


Field separator is "|".
# 5  
Old 05-13-2013
Sorry to confuse.. this mean these 5 fields can be there any where in file or are they first 5 fields of file?

Could you please post some sample data?
# 6  
Old 05-14-2013
these 5 fields are there in every record, at fixed position. Ex:


EmNo. FirstName LastName MidName DOB Gender ZipCode IdentificationID.

Code:
123456 John Kerry   M    26051952 M 760012 123456789
135628 John Kerry    K    26051952 M 760012 123456789
789456 Alex stewart  M  27071972 M 235612 987654321
986542 John Kerry    L    26051952 M 760012 123456789

my O/P shd be:

Code:
123456 John Kerry   M 26051952 M 760012 123456789
789456 Alex stewart  M 27071972 M 235612 987654321

Thanks!!

Last edited by Scott; 05-15-2013 at 01:13 AM.. Reason: Code tags
# 7  
Old 05-14-2013
try..

Code:
awk '!A[$2$3$5$7$8]++'  filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Honey, I broke awk! (duplicate line removal in 30M line 3.7GB csv file)

I have a script that builds a database ~30 million lines, ~3.7 GB .cvs file. After multiple optimzations It takes about 62 min to bring in and parse all the files and used to take 10 min to remove duplicates until I was requested to add another column. I am using the highly optimized awk code: awk... (34 Replies)
Discussion started by: Michael Stora
34 Replies

2. Web Development

Vbseo removal

first off i want to thank you for such a great site, you helped me narrow down a long search on what was wrong with my forum, i have a large forum motorbicycling DOT com which i had someone remove vbseo before they went under because of all the security problems. anyway i have lots of 404 errors... (13 Replies)
Discussion started by: atcspaul
13 Replies

3. Shell Programming and Scripting

Duplicate line removal matching some columns only

I'm looking to remove duplicate rows from a CSV file with a twist. The first row is a header. There are 31 columns. I want to remove duplicates when the first 29 rows are identical ignoring row 30 and 31 BUT the duplicate that is kept should have the shortest total character length in rows 30... (6 Replies)
Discussion started by: Michael Stora
6 Replies

4. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

5. Shell Programming and Scripting

\n removal between two |

I have a multi-line string I'm trying to do some clean-up on. Example: 1|575|67866|"fgnhdgj"|"afhgajh agfajgf ahfjhgfk ahfkhf"|568 2|56|5435|"mayank"|"gupta gdja agdjagf"|677 3|5666|5435|"mayank"|"gupta gdja agdjagf"|677 I need a shell script that replace all \n under " ". (11 Replies)
Discussion started by: mayankgupta18
11 Replies

6. Homework & Coursework Questions

removal of files?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: remove all files and only files that the first three characters start with numerals. 2. Relevant commands,... (6 Replies)
Discussion started by: linuxtraining
6 Replies

7. Shell Programming and Scripting

Removal of Duplicate Entries from the file

I have a file which consists of 1000 entries. Out of 1000 entries i have 500 Duplicate Entires. I want to remove the first Duplicate Entry (i,e entire Line) in the File. The example of the File is shown below: 8244100010143276|MARISOL CARO||MORALES|HSD768|CARR 430 KM 1.7 ... (1 Reply)
Discussion started by: ravi_rn
1 Replies

8. UNIX for Dummies Questions & Answers

Sort, duplicate removal - Query

Hi All, I have a problem with the sort and duplicate filter command I am using in one of my scripts. I have a '|' delimited file and want to sort and remove duplicates on the 1,2,15 fields. These fields constitute the primary key of the table I will be loading the data into. But I see that some... (4 Replies)
Discussion started by: novice1324
4 Replies

9. UNIX for Dummies Questions & Answers

Removal of Data

Hi All, (And first up, a Happy New Year to you all! 363 days to go!) I need to make sure that our old Sun Sparcstations and Servers are clear of any Confidential data before I return them... Suggestions? I'm formatting the discs to make sure that there's nothing obvious, but would... (5 Replies)
Discussion started by: geralex
5 Replies

10. UNIX for Dummies Questions & Answers

Removal

I am using Unix as my OS on my server and would like to format my hard drive. How do I go about wiping my hard drive or is there a removal tool that I can use? (1 Reply)
Discussion started by: anaconda
1 Replies
Login or Register to Ask a Question