Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Any 'shortcut' to doing this search for duplicate and print max Post 302967691 by newbie_01 on Friday 26th of February 2016 10:48:13 AM
Old 02-26-2016
Quote:
Originally Posted by RudiC
How about
Code:
sort -t^ -k2,2n -k4,4nr file | awk '!T[$2]++' FS=^
- [ qual11 ] - QUAL11^901361709^ARCHIVELOG ^11422138368
- [ test11 ] - TEST11^2609333750^ARCHIVELOG^170184688128
- [ test11 ] - TEST11^3637562595^ARCHIVELOG^163462512640
- [ qual11 ] - QUAL11^4014910711^ARCHIVELOG^14071889920

Hi,

I tried your advise and it does work although I need to use nawk on the Solaris 8/9 one.

If you don't mind, may I know what the
Code:
awk '!T[$2]++' FS=^

means? To be more specific the
HTML Code:
'!T[$2]++'
part.

Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print mon and max values of ranges

HI all I'm trying to write an awk script to print the min and max value in a range(s) contained in another file - the range values are in $2 EG 114,7964,1,y,y,n 114,7965,1,y,y,n 114,7966,1,y,y,n 114,7967,1,y,y,n 114,7969,1,y,y,n 114,7970,1,y,y,n 114,7971,1,y,y,n 114,7972,1,y,y,n... (3 Replies)
Discussion started by: Mudshark
3 Replies

2. Shell Programming and Scripting

Search max value in a column in a file instead of sort

Hi Everyone, 1.txt 00:00:00 0 0 0 0 0 0 0 00:00:01 0 0 0 2 1 33 2 00:00:02 5 0 0 0 0 0 0 00:00:03 0 4 0 0 0 0 0... (5 Replies)
Discussion started by: jimmy_y
5 Replies

3. Shell Programming and Scripting

print max number of 2 columns - awk

Is it possible to print max number of 2 columns - awk note: print max if the integer is positive and print min if the integer is negative input a 1 2 b 3 4 c 5 1 d -3 -5 d -5 -3 output a 2 b 4 c 5 d -5 d -5 (4 Replies)
Discussion started by: quincyjones
4 Replies

4. Shell Programming and Scripting

Print min and max value from two column

Dear All, I have data like this, input: 1254 10125 1254 10126 1254 10127 1254 10128 1254 10129 1255 10130 1255 10131 1255 10132 1255 10133 1256 10134 1256 10135 1256 10137... (3 Replies)
Discussion started by: aksin
3 Replies

5. Shell Programming and Scripting

Median and max of duplicate rows

Hi all, plz help me with this, I want to to extract the duplicate rows (column 1) in a file which at least repeat 4 times. then I want to summarize them by getting the max , mean, median and min. The file is sorted by column 1, all the repeated rows appear together. If number of elements is... (5 Replies)
Discussion started by: ritakadm
5 Replies

6. Shell Programming and Scripting

Sum value in a row and print the max

I have the input file in attached. I want the output file : Date , Time , Max_Bearer 11/01/2013 , 23:00 , 1447.894167 11/02/2013 , 00:00 , 1429.266667 11/03/2013 , 00:00 , 712.3175 11/04/2013 , 22:00 , 650.9533333 11/05/2013 , 23:00 , 665.9558333 11/06/2013 , 23:00 , 659.8616667... (2 Replies)
Discussion started by: justbow
2 Replies

7. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

8. Shell Programming and Scripting

Print root number between min and max ranges

Hi to all, Please help on the following problem, I'm not where to begin, if awk or shell script. I have pairs of ranges of numbers and I need to find the root or roots of ranges based on min Range and Max ranges Example #1: If min range is 120000 and max ranges 124999, it means that are... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

9. Shell Programming and Scripting

Find Max value of line and print

I need to find the max value of all columns except the 1st column and print the answer along with the 1st column. Input 123xyz 0 0 1 2 0 0 0 0 0 0 0 234xyz 0 0 0 0 0 0 0 0 0 0 0 345xyz 0 0 1 0 0 0 ... (8 Replies)
Discussion started by: ncwxpanther
8 Replies

10. UNIX for Beginners Questions & Answers

Print a row with the max number in a column

Hello, I have this table: chr1_16857_17742 - chr1 17369 17436 "ENST00000619216.1"; "MIR6859-1"; - 67 chr1_16857_17742 - chr1 14404 29570 "ENST00000488147.1"; "WASH7P"; - 885 chr1_16857_18061 - chr1 ... (5 Replies)
Discussion started by: coppuca
5 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 11:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy