Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:39:47+00:00 2026-05-24T22:39:47+00:00

Given a list like: Dog bone Cat catnip Human ipad Dog collar Dog collar

  • 0

Given a list like:

Dog bone
Cat catnip
Human ipad
Dog collar
Dog collar
Cat collar
Human car
Human laptop
Cat catnip
Human ipad

How can I get results like this, using awk:

Dog bone 1
Dog collar 2
Cat catnip 2
Cat collar 1
Human car 1
Human laptop 1
Human ipad 2

Do I need a sub array? It seems to me like a need an array of “owners” which is populated by arrays of “things.”

I’d like to use awk to do this, as this is a subscript of another program in awk, and for now, I’d rather not create a separate program.

By the way, I can already do it using sort and grep -c, and a few other pipes, but I really won’t be able to do that on gigantic data files, as it would be too slow. Awk is generally much faster for this kind of thing, I’m told.

 Thanks, 
 Kevin

EDIT: Be aware, that the columns are actually not next to eachother like this, in the real file, they are more like column $8 and $11. I say this because I suppose if they were next to eachother I could incorporate an awk regex ~/Dog\ Collar/ or something. But I won’t have that option. -thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:39:48+00:00Added an answer on May 24, 2026 at 10:39 pm

    awk does not have multi-dimensional arrays, but you can manage by constructing 2D-ish array keys:

    awk '{count[$1 " " $2]++} END {for (key in count) print key, count[key]}' | sort
    

    which, from your input, outputs

    Cat catnip 2
    Cat collar 1
    Dog bone 1
    Dog collar 2
    Human car 1
    Human ipad 2
    Human laptop 1
    

    Here, I use a space to separate the key values. If your data contains spaces, you can use some other character that does not appear in your input. I typically use array[$a FS $b] when I have a specific field separator, since that’s guaranteed not to appear in the field values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a simple Ext.List like the one in the Sencha docs, how can I
Given a list like this: num = [1, 2, 3, 4, 5] There are
Given a list of elements like so: int[] ia = new int[] { -4,
Given a list of dictionaries like this: x = [ {'name':'a', 'student': 1 ,
Given A, on the order of 10^20, I'd like to quickly obtain a list
Given a list of elements like this: <ul> <li class=favourite></li> <li class=favourite></li> <li class=favourite></li>
given a list like: 1,3,412,51213,djdd@asdasd.net, blahblah, 123123123123 which lives inside of a input typetext
When given a list of comma separated values like 3, asdf, *#, 1212.3 ,
Ok, so I'm given a list of parts like so: PartID CatID PartName 0
Given a list of tuples like this: dic = [(1,aa),(1,cc),(2,aa),(3,ff),(3,gg),(1,bb)] How to group items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.