Sponsored Content
Full Discussion: awk and sum
Top Forums Shell Programming and Scripting awk and sum Post 303011680 by Scrutinizer on Monday 22nd of January 2018 11:21:22 AM
Old 01-22-2018
Another approach:
Code:
awk '
{
  split($1,F,".")
  i=F[1]
  A[i]=A[i] $0 ","
  T[i]+=$2
}
END {
  for(i in A)
    printf "%ssum-%sGB\n",A[i],T[i]
}
' file

But you did not answer one of Don Cragun's questions in post #2
Quote:
Originally Posted by Don Cragun
[..]
Are all numbers to be added given as "GB" values? Or could "KB", "MB", "TB" and/or other multipliers be present?
This is quite essential, because the approaches in this thread will be fail if the file can also contain KB, MB or TB values.
This User Gave Thanks to Scrutinizer For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk sum columns

can anyone help me how do i add the colums using awk seperated by character @. for eg i have 3@4 2@9 5@1 the result should be 10 14 i tried using { sum+= $1 } END { print sum } but it just gives the result 10. can anyone help me with this one thank you and best regards (7 Replies)
Discussion started by: phone_book
7 Replies

2. Shell Programming and Scripting

Sum with awk

Hi,consider this fields, $1 $2 $3 981 0 1 984 0 4 985 1 0 987 0 2 990 0 0 993 0 3 995 2 0 996 0 1 999 0 4 for each occurence of zero in column $2 and $3 I need to sum $1 fields, so for example, in this piece of code the result of $1 is 8910. I'm sure... (2 Replies)
Discussion started by: cv313x
2 Replies

3. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

4. Shell Programming and Scripting

Sum using awk

Hi all, I need to sum values for fields in a delimited file as below: 2010-03-05||| 2010-03-05|||123 2010-03-05|467.621|369.532| 2010-03-06||| 2010-03-06||2| 2010-03-06|||444 2010-03-07||| 2010-03-07||| 2010-03-07|655.456|1019.301| Code used is: nawk -F "|" ' { sum +=... (7 Replies)
Discussion started by: Katabatic
7 Replies

5. UNIX for Dummies Questions & Answers

awk question about sum

Hi everyone, i need help with a simple task. I have a file withe the format: "01/20/2012 23:10:13.979","49","49","48","19" "01/20/2012 23:15:13.969","47","47","48","18" "01/20/2012 23:20:13.975","47","47","45","17" "01/20/2012 23:25:13.980","44","44","44","17" "01/20/2012... (3 Replies)
Discussion started by: civilianwarfare
3 Replies

6. Shell Programming and Scripting

awk and count sum ?

I have a input.txt file which have 3 fields separate by a comma place, os and timediff in seconds tampa,win7, 2575 tampa,win7, 157619 tampa,win7, 3352 dallas,vista,604799 greenbay,winxp, 14400 greenbay,win7 , 518400 san jose,winxp, 228121 san jose,winxp, 70853 san jose,winxp, 193514... (5 Replies)
Discussion started by: sabercats
5 Replies

7. Shell Programming and Scripting

Sum value using sed or awk ?

Hello all, how would one go about writing a command using sed/awk that will give me an output that can sum up the number of time each user has done something and also add the amount of time... so output would be for example "smiths has run 3 process and for time taken of value: 224" ... (5 Replies)
Discussion started by: crazy_max
5 Replies

8. Shell Programming and Scripting

How to sum the matrix using awk?

input A1 B1 A2 B2 0 0 1 1 1 0 0 1 0 1 1 0 1 1 1 1 Output label A1 B1 A2 B2 A1 2 1 1 2 B1 1 2 2 1 A2 1 2 3 2 B2 2 1 2 3 Ex: The number of times that A1 and B1 row values are both 1 should be printed as output. The last row of A1 and B1 in the input match by having 1 in both... (4 Replies)
Discussion started by: quincyjones
4 Replies

9. Post Here to Contact Site Administrators and Moderators

awk to sum in Loop

i want code in awk with loop to get the sum * is delimiter in file TOTAL_AMOUNT=SUM(CLP04) suppose there are 12 CLP04 segment in my file i want to add upto 5 CLP04 then print next line after BPR segment after calculate the total amount CLP04 means ex ... (5 Replies)
Discussion started by: MOHANP12
5 Replies

10. Shell Programming and Scripting

awk - Print Sum

Hi, I have an awk command that I am using, and part of it sums COL_9 however when I read the output it is not including decimal places; awk ' BEGIN{FS=OFS=","} NR==1{print;next} {a+=$9 c = $12 d = $18 } END{for(i in a) {split(i,b,";"); print $1, $2, $3, b, $5, $6, b, b, a, $10, $11,... (1 Reply)
Discussion started by: Ads89
1 Replies
FSSCONFIG(8)						    BSD System Manager's Manual 					      FSSCONFIG(8)

NAME
fssconfig -- configure file system snapshot devices SYNOPSIS
fssconfig [-cxv] device path backup [cluster [size]] fssconfig -u [-v] device fssconfig -l [-v] [device] DESCRIPTION
The fssconfig command configures file system snapshot pseudo disk devices. It will associate the file system snapshot disk device with a snapshot of path allowing the latter to be accessed as though it were a disk. If backup resides on the snapshotted file system a persistent snapshot will be created. This snapshot is active until backup is unlinked. This snapshot mode is only supported for ffs files systems. Otherwise data written through the path will be saved in backup. If backup is a regular file, it will be created with length size. Default size is the size of path. Data is saved to backup in units of cluster bytes. Options indicate an action to be performed: -c Configures the device. If successful, references to device will access the contents of path at the time the snapshot was taken. If backup is a directory, a temporary file will be created in this directory. This file will be unlinked on exit. -l List the snapshot devices and indicate which ones are in use. If a specific device is given, then only that will be described. -u Unconfigures the device. -v Be more verbose listing the snapshot devices. -x Unlink backup after the device is configured. If no action option is given, -c is assumed. FILES
/dev/rfss? /dev/fss? EXAMPLES
fssconfig fss0 /usr /tmp/back Configures the snapshot device fss0 for a snapshot of the /usr file system. Data written through /usr will be backed up in /tmp/back. fssconfig fss1 / /dev/rsd0e 8192 Configures the snapshot device fss1 for a snapshot of the / file system. Data written through / will be backed up in /dev/rsd0e. The backup will take place in units of 8192 bytes. fssconfig -u fss0 Unconfigures the fss0 device. SEE ALSO
opendisk(3), fss(4), mount(8), umount(8) HISTORY
The fssconfig command appeared in NetBSD 2.0. BSD
June 11, 2012 BSD
All times are GMT -4. The time now is 06:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy