Sponsored Content
Top Forums Shell Programming and Scripting awk summing specific lines and fields Post 302725235 by nakaedu on Friday 2nd of November 2012 12:59:22 AM
Old 11-02-2012
I have to apologize, my original post is not clear enough.
I have removed my original requirement to sum fields $13 and $14 because it is adding complexity and I don't really require them for the moment.
I will try to clarify my requirement,
I have a very long list nearly 1100 lines,
Each line is very similar to these

Code:
x;x;x;x;x;x;x;x;467,390,611 Bytes;0.435291 GB;0.062247 GB;0.373045 GB;11,225;157
a;a;a;a;a;a;a;a;13,805,156,846 Bytes;12.857054 GB;1.838559 GB;11.018495 GB;151,063;18,933
b;b;b;b;b;b;b;b;232,797,478,723 Bytes;216.809547 GB;31.003765 GB;185.805782 GB;176,861;21,445;Parent: Line #545

And I need to sum all fields to obtain: the total number of bytes, and GB. (while removing those lines that contain wording "Parent: Line"

For my example the total number of bytes and gigabytes, would be something similar to:
Code:
14272547457 Bytes;13.292345 GB;1.900806 GB;11.39154 GB

I get those numbers by summing all the row of fields $9, $10, $11, $12

467,390,611 Bytes + 13,805,156,846 Bytes = 14272547457 Bytes
0.435291 GB + 12.857054 GB = 13.292345 GB
0.062247 GB + 1.838559 GB = 1.900806 GB
0.373045 GB + 11.018495 GB = 11.39154 GB

Last edited by nakaedu; 11-02-2012 at 02:04 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

summing up the fields in fixed width file

Hi, I have a fixed width file with some records as given below: " 1000Nalsdjflj243324jljlj" "-0300Njfowjljl309933fsf" " 0010Njsfsjklj342344fsl" I want to sum-up first field values(i.e from 2nd character to 6th character)of each record. so for the above file i want to add (1000 - 300+... (2 Replies)
Discussion started by: srilaxmi
2 Replies

2. UNIX for Dummies Questions & Answers

Updating specific fields with awk using conditions

Can someone help me again, I think with awk? I have a file with 4 columns (pipe-delimited): I just want to convert the last field so that e1 is now 'message 1', e2 is 'message 2', e0 is 'message 3', etc. I don't want to change any other columns because the e0-e10 code may appear as part of a... (4 Replies)
Discussion started by: giannicello
4 Replies

3. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

4. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

5. Shell Programming and Scripting

Summing all fields in a file

I was playing around to see how stuff works, and was trying to sum all fields in a file. cat file 1 2 3 4 5 6 7 8 9 10 11 12 I made this script: awk 'BEGIN {OFS=RS}{$1=$1}{s+=$0} END {print "sum="s}' file This gives 15, why not 78? I test it like this awk 'BEGIN... (5 Replies)
Discussion started by: Jotne
5 Replies

6. UNIX for Dummies Questions & Answers

Read the file and generate specific fields by awk

Hi I need to generate these output file from the below input file. Output : customer_id as customer, zip as zip_cd, catg_cd as catg, Input: out.customer::in.customer_id; out.zip_cd::in.zip; out.catg::in.catg_cd; Could you please help me on this. Please use code tags next... (1 Reply)
Discussion started by: Murugesh
1 Replies

7. Shell Programming and Scripting

Getting max value of specific fields with awk

Hello All, Here is am trying to get maximum value of third field depending on first,second and fourth fields with awk command . delimeter is pipe(|) . input 0221|09|14.25|aaa 0221|09|44.27|aaa 0221|09|44.33|aaa 0221|09|44.53|bbb 0221|09|34.32|bbb 0221|09|37.13|bbb... (5 Replies)
Discussion started by: sayami00
5 Replies

8. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies

9. UNIX for Beginners Questions & Answers

Grep or awk a unique and specific word across many fields

Hi there, I have data with similar structure as this: CHR START-SNP END-SNP REF ALT PATIENT1 PATIENT2 PATIENT3 PATIENT4 chr1 69511 69511 A G homo hetero homo hetero chr2 69513 69513 T C . hetero homo hetero chr3 69814 69814 G C . . homo homo chr4 69815 69815 C A hetero . . hetero is... (10 Replies)
Discussion started by: daashti
10 Replies
OVERVIEW.FMT(5) 						File Formats Manual						   OVERVIEW.FMT(5)

NAME
overview.fmt - format of news overview database DESCRIPTION
The file <pathetc in inn.conf>/overview.fmt specifies the organization of the news overview database. Blank lines and lines beginning with a number sign (``#'') are ignored. The order of lines in this file is important; it determines the order in which the fields will appear in the database. Most lines will consist of an article header name, optionally followed by a colon. A trailing set of lines can have the word ``full'' appear after the colon; this indicates that the header should appear as well as its value. If this file is changed, new overview records will be constructed with the modified format. If it is desired to update existing records, it is necessary to rebuild the existing overview database using makehistory(8) after removing all existing overview files. ``Xref:full'' must be included, or innd(8) and other programs which utilize overview method cannot start. The default file, show below, is compatible with Geoff Collyer's ``nov'' package: Subject: From: Date: Message-ID: References: Bytes: Lines: Xref:full Usually the only modifications which should be made to the default file are additions of new fields to the end of the file; all such fields should have ``full'' after the colon. The first eight fields should remain in the same order as above. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Intended to be compatible with the nov package written by Geoff Collyer <geoff@world.std.com>. This is revision 1.6.6.3, dated 2002/01/05. SEE ALSO
inn.conf(5) OVERVIEW.FMT(5)
All times are GMT -4. The time now is 09:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy