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 8989087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:10:04+00:00 2026-06-15T22:10:04+00:00

TL;DR The idea is : awk ‘{ IP[$1]++; } END { for(var in IP)

  • 0

TL;DR

The idea is :

awk '{
    IP[$1]++;
  }
  END {
    for(var in IP) 
      print IP[var]
  }
}' getline < sockstat | awk '{print $2 "@" $3}' | grep -v '^PROCESS@PID'

I want to count the number of instance of every block in the output from ->
sockstat | awk ‘{print $2 “@” $3}’ | grep -v ‘^PROCESS@PID’

Which looks like:

ubuntu-geoip-pr@2382
chrome@2453
chrome@2453
chrome@2453
chrome@2453
chrome@2453
chrome@2453
chrome@2453
chrome@2453
rhythmbox@4759
rhythmbox@4759
rhythmbox@4759

Finally, I want to get the output as:

1
8
3

This corresponds to the number of occurrences of each of the items in the previous output.

Problem in full:

The sockstat command outputs the info for some networking stats for the localhost. I first print out a single key from the second and third columns from the output (PROCESS and PID, respectively), in the form PROCESS@PID. Then, I want to calculate the frequency of each unique key from that output. One way to do this is to use the awk getline structure, but that seems works for files, and I have not been able to make it pull input directly from the above command.

I do not want to use temporary files, as that takes away the elegance of the solution.

  • 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-06-15T22:10:05+00:00Added an answer on June 15, 2026 at 10:10 pm
    sockstat | awk '{print $2 "@" $3}' | grep -v '^PROCESS@PID' | sort | uniq -c | awk '{print $1}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Idea: I want to make smth like real time electronic blackboard. Many users have
Any idea on how can I track users bookmarking event? I want to find
Often I want to get a nice readout what process are running and their
Any idea why the following code will not compile? IEnumerable users; using (var ent
I am using AWK script to process some logs. At one place I need
I want to use grep with the -f, -i, and -v options. I have
Using IDEA 9/10, I don't want to use MVN2 anymore (reasons mostly similar to
I have a file with a number of fields that I want to tweak
idea Via jQuery, I was able to mark all :first-child and :last-child elements in
idea I would like to create a little app for myself to store ideas

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.