Sponsored Content
Top Forums Shell Programming and Scripting Find duplicate based on 'n' fields and mark the duplicate as 'D' Post 302593716 by rdcwayx on Saturday 28th of January 2012 06:34:36 AM
Old 01-28-2012
Code:
awk '{s=$1 FS $2 FS $3} 
     NR==FNR{a[s]++;b[s]=FNR;next}
     FNR==1{print;next} 
     {if (a[s]<2)
           {print}
      else
           {print (b[s]==FNR)?$0 "|C":$0 "|D"}}' FS=\| OFS=\| infile infile

These 2 Users Gave Thanks to rdcwayx For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract duplicate fields in rows

I have a input file with formating: 6000000901 ;36200103 ;h3a01f496 ; 2000123605 ;36218982 ;heefa1328 ; 2000273132 ;36246985 ;h08c5cb71 ; 2000041207 ;36246985 ;heef75497 ; Each fields is seperated by semi-comma. Sometime, the second files is... (6 Replies)
Discussion started by: anhtt
6 Replies

2. Shell Programming and Scripting

compare fields in a file with duplicate records

Hi: I've been searching the net but didnt find a clue. I have a file in which, for some records, some fields coincide. I want to compare one (or more) of the dissimilar fields and retain the one record that fulfills a certain condition. For example, on this file: 99 TR 1991 5 06 ... (1 Reply)
Discussion started by: rleal
1 Replies

3. Shell Programming and Scripting

awk 2 fields duplicate and 1 different

I have file that I need to remove the duplicates. The problem is, I need to only keep the one which has a unique 3rd field. Here is a sample file: xxx.xxx:x:CISCO1.CLEVE61W:ERIE.NET:x:x:x:x: xxx.xxx:x:CISCO2.CLEVE62W:OHIO.NET:x:x:x:x: xxx.xxx:x:CISCO2.CLEVE62W:NORTH.NET:x:x:x:x:... (1 Reply)
Discussion started by: numele
1 Replies

4. Shell Programming and Scripting

Filter or remove duplicate block of text without distinguishing marks or fields

Hello, Although I have found similar questions, I could not find advice that could help with our problem. The issue: We have several hundreds text files containing repeated blocks of text (I guess back at the time they were prepared like that to optmize printing). The block of texts... (13 Replies)
Discussion started by: samask
13 Replies

5. Shell Programming and Scripting

Remove duplicate based on Group

Hi, How can I remove duplicates from a file based on group on other column? for example: Test1|Test2|Test3|Test4|Test5 Test1|Test6|Test7|Test8|Test5 Test1|Test9|Test10|Test11|Test12 Test1|Test13|Test14|Test15|Test16 Test17|Test18|Test19|Test20|Test21 Test17|Test22|Test23|Test24|Test5 ... (2 Replies)
Discussion started by: yale_work
2 Replies

6. Shell Programming and Scripting

Join fields from files with duplicate lines

I have two files, file1.txt: 1 abc 2 def 2 dgh 3 ijk 4 lmn file2.txt 1 opq 2 rst 3 uvw My desired output is: 1 abc opq 2 def rst 2 dgh rst 3 ijk uvw (2 Replies)
Discussion started by: xan.amini
2 Replies

7. Shell Programming and Scripting

How To Remove Duplicate Based on the Value?

Hi , Some time i got duplicated value in my files , bundle_identifier= B Sometext=ABC bundle_identifier= A bundle_unit=500 Sometext123=ABCD bundle_unit=400 i need to check if there is a duplicated values or not if yes , i need to check if the value is A or B when Bundle_Identified ,... (2 Replies)
Discussion started by: OTNA
2 Replies

8. Shell Programming and Scripting

Remove duplicate lines from file based on fields

Dear community, I have to remove duplicate lines from a file contains a very big ammount of rows (milions?) based on 1st and 3rd columns The data are like this: Region 23/11/2014 09:11:36 41752 Medio 23/11/2014 03:11:38 4132 Info 23/11/2014 05:11:09 4323... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

9. Shell Programming and Scripting

Find duplicate values in specific column and delete all the duplicate values

Dear folks I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Discussion started by: sajmar
4 Replies

10. UNIX for Beginners Questions & Answers

Discarding records with duplicate fields

Hi, My input looks like this (tab-delimited): grp1 name2 firstname M 55 item1 item1.0 grp1 name2 firstname F 55 item1 item1.0 grp2 name1 firstname M 55 item1 item1.0 grp2 name2 firstname M 55 item1 item1.0 Using awk, I am trying to discard the records with common fields 2, 4, 5, 6, 7... (4 Replies)
Discussion started by: beca123456
4 Replies
cdb(1)							      General Commands Manual							    cdb(1)

NAME
cdb - Constant DataBase manipulation tool SYNOPSYS
cdb -q [-m] [-n num] dbname key cdb -d [-m] [dbname|-] cdb -l [-m] [dbname|-] cdb -s [dbname|-] cdb -c [-m] [-t tmpname|-] [-p perms] [-weru0] dbname [infile...] DESCRIPTION
cdb used to query, dump, list, analyze or create CDB (Constant DataBase) files. Format of cdb described in cdb(5) manpage. This manual page corresponds to version 0.78 of tinycdb package. Query cdb -q finds given key in a given dbname cdb file, and writes associated value to standard output if found (and exits with zero), or exits with non-zero if not found. dbname must be seekable file, and stdin can not be used as input. By default, cdb will print all records found. Options recognized in query mode: -nnum causes cdb to find and write a record with a given number num starting with 1 -- when there are many records with a given key. -m newline will be added after every value printed. By default, multiple values will be written without any delimiter. Dump/List cdb -d dumps contents, and cdb -l lists keys of cdbfile (or standard input if not specified) to standard output, in format controlled by presence of -m option. See subsection "Formats" below. Output from cdb -d can be used as an input for cdb -c. Create Cdb database created in two stages: temporary database is created, and after it is complete, it gets atomically renamed to permanent place. This avoids requirements for locking between readers and writers (or creaters). cdb -c will attempt to create cdb in file tmpname (or dbname with ".tmp" appended if no -t option given) and then rename it to dbname. It will read supplied infiles (or standard input if none specified). Options recognized in create mode: -t tmpname use given tmpname as temporary file. Defaults to dbname.tmp (i.e. with output file with .tmp added). Note tmpname must be in the same filesystem as output file, as cdb uses rename(2) to finalize the database creation procedure. If tmpname is a single dash (-), no temp file will be created, database will be built in-place. This mode is useful when the final renaming is done by the caller. -p perms permissions for the newly created file (usually an octal number, like 0644). By default the permissions are 0666 (with current process umask applied). If this option is specified, current umask value has no effect. -w warn about duplicate keys. -e abort on duplicate keys (implies -w). -r replace existing key with new one in case of duplicate. This may require database file rewrite to remove old records, and can be slow. -0 zero-fill existing records when duplicate records are added. This is faster than -r, but leaves extra zeros in the database file in case of duplicates. -u do not add duplicate records. -m interpret input as a sequence of lines, one record per line, with value separated from a key by space or tab characters, instead of native cdb format (see "Input/Output Format" below). Note that using any option that requires duplicate checking will slow creation process significantly, especially for large databases. Statistics cdb -s will analyze dbfile and print summary to standard output. Statistics include: total number of rows in a file, minimum, average and maximum key and value lengths, hash tables (max 256) and entries used, number of hash collisions (that is, more than one key point to the same hash table entry), minimum, average and maximum hash table size (of non-empty tables), and number of keys that sits at 10 different distances from it's calculated hash table index -- keys in distance 0 requires only one hash table lookup, 1 -- two and so on; more keys at greater distance means slower database search. Input/Output Format By default, cdb expects (for create operation) or writes (for dump/list) native cdb format data. Cdb native format is a sequence of records in a form: +klen,vlen:key->val where "+", ",", ":", "-", ">" and " " (newline) are literal characters, klen and vlen are length of key and value as decimal numbers, and key and val are key and value themselves. Series of records terminated by an empty line. This is the only format where key and value may contain any character including newline, zero () and so on. When -l option requested (list keys mode), cdb will produce slightly modified output in a form: +klen:key (note vlen and val are omitted, together with surrounding delimiters). If -m option is given, cdb will expect or produce one line for every record (newline is a record delimiter), and every line should contain optional whitespace, key, whitespace and value up to end of line. Lines started with hash character (#) and empty lines are ignored. This is the same format as mkmap(1) utility expects. OPTIONS SUMMARY
Here is a short summary of all options accepted by cdb utility: -0 zero-fill duplicate records in create (-c) mode. -c create mode. -d dump mode. -e abort (error) on duplicate key in create (-c) mode. -h print short help and exit. -l list mode. -m input or output is in "map" format, not in native cdb format. In query mode, add a newline after every value written. -nnum find and print numth record in query (-q) mode. -q query mode. -r replace duplicate keys in create (-c) mode. -s statistics mode. -t tempfile specify temporary file when creating (-c) cdb file (use single dash (-) as tempfile to stop using temp file). -u do not insert duplicate keys (unique) in create (-c) mode. -w warn about duplicate keys in create (-c) mode. AUTHOR
The tinycdb package written by Michael Tokarev <mjt@corpit.ru>, based on ideas and shares file format with original cdb library by Dan Bernstein. SEE ALSO
cdb(5), cdb(3). LICENCE
Public domain. Jan 2009 cdb(1)
All times are GMT -4. The time now is 03:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy