The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Monkcast #12: IBM HW group OEMs Solaris to chagrin of SW group & a ... - ZDNet.com bl iBot UNIX and Linux RSS News 0 08-17-2007 05:30 PM
Count No of Records in File without counting Header and Trailer Records guiguy Shell Programming and Scripting 2 06-07-2007 01:15 PM
find and group records in a file thumsup9 UNIX for Advanced & Expert Users 20 04-19-2007 06:04 PM
Select records based on search criteria on first column shashi_kiran_v UNIX for Dummies Questions & Answers 2 12-02-2005 01:49 PM
entry in /etc/group too long - problem using sudo with %group poli SUN Solaris 4 12-21-2004 09:50 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-20-2009
sandeep13 sandeep13 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 8
Hi Guys,

Once again I have a query regarding grouping the columns, below is my requirement:

Input File:
COL1; COL2; AMT1;AMT2
PORT1;CURR1;100;50
PORT1;CURR1;200;100
PORT2;CURR2;300;150
PORT3;CURR3;400;200
PORT3;CURR3;500;250

Expected Output:
COL1; COL2; AMT1;AMT2
PORT1;CURR1;300;150
PORT2;CURR2;300;150
PORT3;CURR3;900;450

How can I pass to values in below command:
/usr/bin/nawk 'BEGIN{FS=OFS=";"}NR==1{print;next}{a[$1";"$2]+=$3}END{for(i in a)print i, a[i]}' <INPUT FILE>

Please suggest so that I can get both AMT1 and AMT2 gouped by COL1 and COL2.
Thanks in advance.

Regards,
Sandeep
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 03:43 AM.


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