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
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 11:25 AM
how to access values of awk/nawk variables outside the awk/nawk block? saniya Shell Programming and Scripting 5 05-13-2008 04:37 AM
nawk/ksh help DeltaX Shell Programming and Scripting 0 03-06-2008 12:54 PM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
help with Awk or nawk Gerry405 UNIX for Dummies Questions & Answers 2 11-28-2005 10:00 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
nawk array help

This is a derivative of a question I asked earlier, but I can't figure out how to make all of the pieces work (mainly the array piece).

How do I get the following data set:
aaa|bbb|ccc|123|ddd...
abc|def|ghi|123|jkm...
aaa|bbb|ccc|456|ddd...
abc|def|ghi|456|jkm...
aaa|bbb|ccc|789|ddd...
abc|def|ghi|789|jkm...

to look like:
aaa|bbb|ccc|123|ddd...
abc|def|ghi|123|jkm...

Bascially I need to dedupe the file and I don't care which of the multiples I end up with. Also since the file layout can be multiple lenghts I was thinking about using $0 to just cover my bases.

My name says it all. Help!
Reply With Quote
Forum Sponsor
  #2  
Old 04-15-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Oh, I almost forgot, the only field that is used in matching is the first field - the "aaa" or "abc".
Reply With Quote
  #3  
Old 04-15-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
awk -F '|' '!a[$1]++' file1
Reply With Quote
  #4  
Old 04-16-2008
Registered User
 

Join Date: Apr 2008
Posts: 7
Quote:
Originally Posted by Ygor View Post
Try...
Code:
awk -F '|' '!a[$1]++' file1
It works great! Any chance you could explain what you did?

Thanks.
Reply With Quote
  #5  
Old 04-16-2008
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
http://www.unix.com/83360-post7.html
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:51 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0