Duplicate removal


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Duplicate removal
# 8  
Old 05-14-2013
Thanks Vidya,

The script which you have given is working only for the records which is separated by white space .

since my file is positional may not contain white space always so please help me how to write script for this scenario.

Code:
0033912087101ASIM                          JOHN           W19210403MEE4101 W ILES AVE APT 2215                                    SPRINGFIELD         IL62711-0000NN

this is one sample record we are eliminating duplicates based on this 5 fields and respective positions
Code:
field             POSITION(START POS -END POS)
CUSTNO -     3-11
LNAME   -     14-30
FNAME   -     44-59
DOB      -      60-68
zip        -      153-163

please help me to write the script based on above scenario

Last edited by Scott; 05-15-2013 at 01:14 AM.. Reason: Code tags
# 9  
Old 05-14-2013
in that case you can try below..

Code:
awk '!A[substr($0,3,9)substr($0,14,17)substr($0,44,16)substr($0,60,9)substr($0,153,11)]++' filename

If there is changes in position feel free to make changes to it
# 10  
Old 05-14-2013
Thanks Vidya,


Its working fine .


I have a scenario what if the input file doesnt have duplicate records how can i handle the error

Should i have to handle any errors.
# 11  
Old 05-15-2013
If file doesnt have any duplicate record I dont think you have to handle any error messages.. Again it depends on your requirements Smilie

Regards,
Vidya
# 12  
Old 05-15-2013
Thanks Vidya,

can you please explain what does this mean(functionality) :awk '!A

Code:
awk '!A[substr($0,3,9)substr($0,14,17)substr($0,44,16)substr($0,60,9)substr($0,153,11)]++' filename


Last edited by Scott; 11-25-2013 at 05:10 AM.. Reason: Code tags
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