The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating an array to hold posix thread ids: Only dynamic array works kmehta High Level Programming 4 09-21-2008 09:24 PM
split and making an array inside another array dcfargo Shell Programming and Scripting 2 08-06-2008 11:07 AM
need some help..Comparison bluesilo Shell Programming and Scripting 0 02-23-2008 04:43 PM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 09:42 AM
comparison cnf Filesystems, Disks and Memory 2 05-14-2002 02:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
Help with array comparison

I have an array @name with the below contents (index 7 and 8 are names):

1|1|2|2|I|2|0|DUNN|LACY||||||
2|2|2|2|I|2|0|KOFE|ROGER||||||
3|3|2|2|A|2|0|KOFOED|ROBERT||||||
3|4|2|2|A|2|0|KOFOED|ROBERT||||||
3|5|2|2|A|2|0|KOFOED|ROBERT||||||
2|7|2|2|I|2|0|WILLIAMSON|JAMES||||||
3|8|2|2|I|2|0|MUNN|MARION||||||
4|9|2|2|A|2|0|BLOCK|ROY||||||

I want to remove the duplicates, from the list @name:

1|1|2|2|I|2|0|DUNN|LACY||||||
2|2|2|2|I|2|0|KOFE|ROGER||||||
3|3|2|2|A|2|0|KOFOED|ROBERT||||||
2|7|2|2|I|2|0|WILLIAMSON|JAMES||||||
3|8|2|2|I|2|0|MUNN|MARION||||||
4|9|2|2|A|2|0|BLOCK|ROY||||||

I need help with a unique list of names (ignore the other fields).

Thanks,

- CB
  #2 (permalink)  
Old 11-13-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
What programming language you're using?
  #3 (permalink)  
Old 11-13-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
this is perl
  #4 (permalink)  
Old 11-13-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,928
I'm not sure if this is an array or input.
Anyway, consider the following approach:


Code:
#! /usr/bin/perl

use warnings;
use strict;

my %Seen;

while (<DATA>) {
  print unless $Seen{(split /\|/)[7,8]}++;
  }


__DATA__
1|1|2|2|I|2|0|DUNN|LACY||||||
2|2|2|2|I|2|0|KOFE|ROGER||||||
3|3|2|2|A|2|0|KOFOED|ROBERT||||||
3|4|2|2|A|2|0|KOFOED|ROBERT||||||
3|5|2|2|A|2|0|KOFOED|ROBERT||||||
2|7|2|2|I|2|0|WILLIAMSON|JAMES||||||
3|8|2|2|I|2|0|MUNN|MARION||||||
4|9|2|2|A|2|0|BLOCK|ROY||||||

Which produces:


Code:
$ ./p  
1|1|2|2|I|2|0|DUNN|LACY||||||
2|2|2|2|I|2|0|KOFE|ROGER||||||
3|3|2|2|A|2|0|KOFOED|ROBERT||||||
2|7|2|2|I|2|0|WILLIAMSON|JAMES||||||
3|8|2|2|I|2|0|MUNN|MARION||||||
4|9|2|2|A|2|0|BLOCK|ROY||||||

You may try join '|', (split /\|/)[7,8] as a hash key for more precise processing.
  #5 (permalink)  
Old 11-13-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
This will be an array
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0