Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cant get awk 1liner to remove duplicate lines from Delimited file, get "event not found" error..help
# 1  
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
# 2  
Old 04-08-2013
In Solaris / SunOS try using /usr/xpg4/bin/awk or nawk
# 3  
Old 04-09-2013
"event not found" is an error in csh/tcsh when it meets an un-escaped !. Other shells handle it better.
Try to avoid the !
Code:
awk '0==x[$1 FS $2]++' FS="," File1.dat

Better, avoid csh/tcsh!
Code:
exec bash
echo 'hello !world!'

# 4  
Old 04-09-2013
Perl
Code:
perl -nle '@flds=split(/,/);
if (not exists ($seen{$flds[0].",".$flds[1]})) {
$seen{$flds[0].",".$flds[1]}=$_;
}
END{
print $seen{$_} foreach (keys %seen);}' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
Login or Register to Ask a Question