LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-19-2008, 10:28 AM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL, CentOS, Ubuntu
Posts: 333

Rep: Reputation: 17
nawk question - addition of a column


Hi,

I have a file, like the following, where I would like to addition up column 5 (length).

DISK DEVICE TAG OFFSET LENGTH FLAGS
ARG01-05_CU0212 c3t110d2s2 c3t110d2 25186048 2076928 -
ARG03-15_CU0561 c3t110d0s2 c3t110d0 16777216 4171520 -
ARG03-15_CU0562 c3t110d1s2 c3t110d1 4194304 16754432 -


cat out | nawk -F" " '/[0-9]+/ { sum += $5 ; print $sum}'

Above is the nawk that I am trying. Firstly check it's a number, and then addition up column 5. I read a few random web-pages, and I thought this would work, but does'nt...

I am using nawk on Solaris although I think that nawk exists on many Linux distributions too.

Many thanks for any tips.
 
Old 02-19-2008, 11:47 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Code:
nawk ' /-$/ {sum+=$5} END{ printf("%12.0f\n", sum)} ' file
23002880
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing non-unique record in nawk omega71122 Linux - Software 4 05-03-2006 10:45 AM
SQL question: Need to add a column from another table Hivemind Programming 3 09-19-2005 06:02 PM
Nawk output omega71122 Solaris / OpenSolaris 3 08-16-2005 03:40 PM
nawk not available raees Linux - Software 3 05-02-2005 03:49 PM
Nawk issues michedlp Programming 1 02-25-2004 07:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration