?
Solved

Sort by one column, total in another column

Posted on 2012-03-11
2
Medium Priority
?
456 Views
Last Modified: 2012-04-02
seq1, content=xxx, size=400
seq2, content=xxx, size=500
seq3, content=aaa, size=300
seq3, content=aaa, size=200
seq3, content=bbb, size=200
..
...


zcat myfile.txt.gz | awk '{print $2}' |  sort | uniq -c | sort -rn |more

600000 content=xxx
500000 content=yyy
400000 content=zzz
300000 content=aaa
4000 content=bbb
2000 content=ccc



Now what I want is i have counts of content  ($2) and their size total ($3).

600000 content=xxx, 500000
500000 content=yyy, 444444
400000 content=zzz, 42344
300000 content=aaa, 234234
4000 content=bbb, 3252345
2000 content=ccc, 2345234

or something like that.

thanks.


W
0
Comment
Question by:williamwlk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 37708689
zcat myfile.txt.gz | awk -F',|='  '{c[$3]+=1; s[$3]+=$5} END {for(n in c) print c[n], n "," s[n]}' | sort -rn

The above will neither regard nor display the "content=" part. If you need to take this string into account use this:

zcat myfile.txt.gz | awk -F',|=' '{c[$2"="$3]+=1; s[$2"="$3]+=$5} END {for(n in c) print c[n], n "," s[n]}' | sort -rn

To avoid working on empty lines add this, if needed:

zcat myfile.txt.gz | awk -F',|='  '!/^$/ { .......

(remainder of the commands same as above).
0
 

Author Closing Comment

by:williamwlk
ID: 37797339
Sorry about my late response, Dear Expert! Thank you so much for the code! Appreciate it.
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question