Sponsored Content
Top Forums Shell Programming and Scripting Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help Post 302791503 by andy b on Monday 8th of April 2013 03:25:16 PM
Old 04-08-2013
Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help

Hi,

I am on a Solaris8 machine

If someone can help me with adjusting this awk 1 liner (turning it into a real awkscript) to get by this "event not found error"

...or

Present Perl solution code that works for Perl5.8 in the csh shell ...that would be great.
******************

Here is the comma delimited InputFile i have (File1.dat):

It has (7 records each with 3 fields)

I want to define a duplicate record as any record where Field1 & Field2 values repeat across 2 or more records so that in by input file below...I have 3 duplicate records. Then I want to only keep the 1st occurrence of this duplicate record.

kk,12,a
aa,11,n --> duplicate
ee,13,b
aa,11,f --> duplicate
bb,17,k
pp,12,t
aa,11,w --> duplicate

What I want my awk script or perlscript to do is produce the following output (that is reduce the file from the 7records to 5records) , in essence keeping the 1st duplicate line, record only (again duplicate is defined as Field1 & Field2 having the same value across the records)

Desired Output File is here (5records, it kept only the 1st duplicate):

kk,12,a
aa,11,n
ee,13,b
bb,17,k
pp,12,t

I tried the following awk 1-liner at the csh prompt

awk '!x[$1,$2]++' FS="," File1.dat

but got the error message "Event not found"

***********

If someone knows how i can correct the above awk 1liner or how to make an alternative multi-line awk or perl script to do this ..that okay with me also. Just let me know where in your code it references

a) the fact that the files are comma delmited
b) Field1 & Field 2 as the fields by which to classify a record as a duplicate

Thanks in advance (this has stumped me for hours ..)

andy b
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

2. Shell Programming and Scripting

Need to parse file "x" lines at a time ... awk array?

I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line: Column 1 is a common number for the entire file and all devices in that file Column 2 is a unique device number Column 3 is... (7 Replies)
Discussion started by: STN
7 Replies

3. Shell Programming and Scripting

Remove ":" and join lines in outline file

I have a vim outliner file like this: Title title 2 :Testing now :testing 2 :testing 3 title 3 :testing :ttt :ttg Is there a way to use a script or command to remove... (7 Replies)
Discussion started by: jostber
7 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Perl- Finding average "frequency" of occurrence of duplicate lines

Hello, I am working with a perl script that tries to find the average "frequency" in which lines are duplicated. So far I've only managed to find the way to count how many times the lines are repeated, the code is as follows: perl -ae' my $filename= $ENV{'i'}; open (FILE, "$filename") or... (10 Replies)
Discussion started by: acsg
10 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Red Hat

Could interrupt disabled cause "opreport error: No sample file found"?

Hi All I would like to profile my application with oprofile but I can't since no samples are collected. The kernel of my app is 2.6 on RED HAT Enterprise 5.3 (Tikanga) so OProfile is setup in timer interrupt mode # opcontrol --list-events Using timer interrupt. I... (0 Replies)
Discussion started by: manustone
0 Replies

8. Shell Programming and Scripting

Delete till ">" is found in all lines in a file

Hi, I have a file which has lines like these : I want to trim everything from the left till ">" such that the file looks like : If you have any ideas how to do this in 1-2 commands please help. Thanks. (3 Replies)
Discussion started by: sinpeak
3 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 08:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy