Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorta need help on sorting with awk 1

Status
Not open for further replies.

dirons

Technical User
Feb 11, 2002
1
US
First of all I do not have access to the unix sort -u command. I have this file which I need to get all of the
unique lines out of. Please help.

Here's an example of the file:

A!CLASS!SUBCLASS!
J!D:\Allegro_extractions\new_nt_extractions\cdsfab\pcb.brd!Thu Feb 07 16:36:19 2002!-7155.974!-3086.000!35770.000!26914.000!0.001!mils!!72.0874 mil!8!UP TO DATE!
S!ETCH!BOT!
S!ETCH!LY2!
S!ETCH!LY3!
S!ETCH!LY4!
S!ETCH!LY4!
S!ETCH!LY4!
S!ETCH!LY4!
S!ETCH!LY4!
S!ETCH!LY5!
S!ETCH!LY5!
S!ETCH!LY5!
S!ETCH!LY5!
S!ETCH!LY5!
S!ETCH!LY5!
 
I assume the file is sorted. If so, this awk program will remove duplicate lines.
Code:
{
  if (a != $0) {
    print
    a = $0
  }
}
Hope this helps.

CaKiwi
 
This awk command prints only unique lines even input data isn't sorted, but output is unsorted:

Code:
awk '{ a[$0] = $0 }  END { for (i in a) print i }' inputfile

I use array (awk's arrays are associative); this is a powerful awk-tool.

Bye!

KP.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top