The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert two column data into 8 columns NickC Shell Programming and Scripting 8 06-28-2008 12:19 PM
Single column to multiple columns in awk astroDave Shell Programming and Scripting 2 03-27-2008 10:00 PM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
single column to multiple columns agibbs UNIX for Dummies Questions & Answers 7 12-05-2007 10:04 PM
Print last 4 columns (variable column #) Da_Duck UNIX for Dummies Questions & Answers 19 02-27-2004 10:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2008
kaustubh137 kaustubh137 is offline
Registered User
  
 

Join Date: May 2008
Posts: 17
Count first column on the basis of two other columns

Hello,

I have a file
=================
12 SRV1 GRP1
19 SRV1 GRP1
19 SRV1 GRP2
3 SRV1 GRP1
3 SRV1 GRP2
30 SRV1 GRP2
7 SRV1 GRP1
8 SRV1 GRP3
===========

I want output like
===============
41 SRV1 GRP1
52 SRV1 GRP2
8 SRV1 GRP3

Basically I want to calculate the count of first column based on other 2 columns.

Thanks in advance.
  #2 (permalink)  
Old 05-29-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,428
Something like that ?
Code:
awk '
{ sum[$2 OFS $3] += $1 }
END { for (f in sum) print sum[f],f }
' inputfile > outputfile
Jean-Pierre.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0