Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Posts
    41

    Unanswered: how to find distinct type of records in UNIX

    Hi,

    I've a flat file where 1st two bytes of each record is an identifier for that record. How do I find distinct count of these records?

    Flat file ex:

    AB|123|hello moto|
    AB|456|googly|
    BC|sick day|booya|
    ID|inter doing|hahahah

    So I want to find distinct record count...

    it should give me

    AB 2
    BC 1
    ID 1

    Pls help.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking


    Try this:

    awk -F'|' '{++c[$1]}END{for(i in c)print i,c[i]}' FlatFile.txt


    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Mar 2005
    Posts
    41

    Wink Thanks so much

    it works, rock on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •