perl/shell need help to remove duplicate lines from files

Dear All,

I have multiple files having number of records, consist of more than 10 columns some column values are duplicate and i want to remove these duplicate values from these files.
Duplicate values may come in different files.... all files laying in single directory..

Need help to remove line contain duplicate values, and store in another files with same file name having .dup extention...

Sample files
Input_file_001.txt

AAAAAC01            0397fa           AB2010120211200500000000200009904136515                 099999999999                 IUVSN11                                 MOB
          AAAAAA01  03981d           AB2010120211130100000007430009588004780                 888888888888888                                 GGGCZ11                     MOB                                              76457499048         3122
          BBBBBBB01  03982f           AB2010120211203400000000150009588000696                 909090909090909                                 KKKKKG11                     MOB                                              64325984725         4107
AAAAAC01            0396fa           AB2010120211200500000000200009904136515                 099999999999                 IUVSN11                                 MOB ------ contain duplicate value
          AAAAAA01  03901d           AB2010120211130100000007430009588004780                 888888888888888                                 GGGCZ11                     MOB                                              76457499048         3122 ------ contain duplicate value

Input_file_002.txt

CCCCCCA01  03981d           AB2010120211130100000007430009588004780                 11111111111118                                 GGGCZ11                     MOB                                              76457499048         3122
          BBBBBBB01  03932f           AB2010120211203400000000150009588000696                 909090909090909                                 KKKKKG11                     MOB                                              64325984725         4107 � contain duplicate values of first file

Need out put something like this
Input_file_001.txt

AAAAAC01            0397fa           AB2010120211200500000000200009904136515                 099999999999                 IUVSN11                                 MOB
          AAAAAA01  03981d           AB2010120211130100000007430009588004780                 888888888888888                                 GGGCZ11                     MOB                                              76457499048         3122
          BBBBBBB01  03982f           AB2010120211203400000000150009588000696                 909090909090909                                 KKKKKG11                     MOB                                              64325984725         4107

Input_file_001.txt.dup

AAAAAC01            0396fa           AB2010120211200500000000200009904136515                 099999999999                 IUVSN11                                 MOB 
          AAAAAA01  03901d           AB2010120211130100000007430009588004780                 888888888888888                                 GGGCZ11                     MOB                                              76457499048         3122 

Input_file_002.txt

CCCCCCA01  03981d           AB2010120211130100000007430009588004780                 11111111111118                                 GGGCZ11                     MOB                                              76457499048         3122

Input_file_002.txt.dup

BBBBBBB01  03932f           AB2010120211203400000000150009588000696                 909090909090909                                 KKKKKG11                     MOB                                              64325984725         4107 

Currently i�m using following command to remove duplicate.... but not able to store duplicate lines .dup file

awk '!x [substr($0,38,93), substr($0,94,141)]++'   * > all_files_

If we are talking utterly duplicate lines, it can get VM intensive to do it all in memory so you can preserve order. Are duplicate lines always in the same file? Here is a robust dup finder using sort:

for file in *.txt
do
  sort $file|uniq -d >>$file.dups
  if [ ! -s $file.dups ]
  then
    rm -f $file.dups
  fi
done

You only get one copy of each dup.

duplicate lines may contain in different files... :frowning:

duplicate need to identify if substr($0,38,93), substr($0,94,141) values are duplicate

thank you

OK, A. the key is not the whole line, and B. duplicates across files are bad, two complications. Reporting the duplicate means a definition of the original, expecially for non-key data.

  • If the lines have identical keys and not identical payload (fields not keys), then will file name order and order in file pick a winner?
  • We need to survey all files for duplicate keys, then extract the unique and winners to load, and the losers to report. Think of them as two important products, not picking favorites. While most days there may be no duplicates, if one day there are tons, you still want it to blast through.
  • There are two approaches to dealing with duplicate filtering. You can save every key in an associative array (magic box that recalls by value, but may not be robust in speed and stability with huge volume) or you can sort in key, priority order (more traditional and quite robust if you have the disk space. Store just the last key, process the first of every key and log the others. Worked great on tape in 1960 with 16K or RAM! :slight_smile:
  • Tagging the duplicates by original file means adding the file name to every record, possible but a bit of a luxury if not needed.