Sponsored Content
Top Forums Shell Programming and Scripting Awk help needed to calculate total Post 302227440 by senthilkumar_ak on Thursday 21st of August 2008 08:19:21 AM
Old 08-21-2008
Awk help needed to calculate total

Hi all,

I have a flat file like

10 steven
25 mike
47 Charles
127 Nancy
34 steven
23 mike
67 Charles
7761 Nancy
8 steven
54 mike
88 Charles
1267 Nancy

I need to calculate the total of steven and all the members , for this I am using like

grep "`sed -n 1p patterns.txt`" temp.log | awk '{x+=$1}END{print "Total "x}'

where patterns.txt contains
steven
mike
Charles
Nancy

I think i'm using wrong method, is there any other method is available which can do this job very easily.

Regards,
senthilkumar ak
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to calculate total

Hi First field is the Record Type. A Record Type 5 can have multiple Record Type 6's before another Record Type 5 appears. I want to calculate the total of fields at position 8-11 on Record type 6 when Record Type 5 has a field at position 11-14 equals to '2222'. then it should delete the lines... (2 Replies)
Discussion started by: appsguy616
2 Replies

2. Shell Programming and Scripting

Calculate total sum from a file

The file content is dynamic and using this format: name1 number1 name2 number2 name3 number3 name4 number4 .................... Need a smooth way to calculate the sum of all the numbers in that file (number1 + number2 + number3 + number4........ = total ) (11 Replies)
Discussion started by: TehOne
11 Replies

3. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

4. Shell Programming and Scripting

Help with calculate total sum of same data problem

Long list of input file: AGDRE1 0.1005449050 AGDRE1 2.1005443435 AGDRE1 1.2005449050 AGDRE1 5.1005487870 AASFV3 50.456304789 AASFV3 2.3659706549 AASFV3 6.3489807860 AASFV3 3.0089890148 RTRTRS 5.6546403546 . . Desired output file: AGDRE1 8.5021829410 AASFV3 62.180245240... (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Calculate total of log by hour

Hi, Just wondering, is there anyway I can get the total of logs generated by hours ? Let say I have these logs, Sep 23 04:48:43 hsbcufs: NOTICE: realloccg /: file system full Sep 23 04:48:47 hsbcufs: NOTICE: alloc: /: file system full Sep 23 04:48:51 hsbcufs: NOTICE: realloccg /: file... (14 Replies)
Discussion started by: dehetoxic
14 Replies

6. Shell Programming and Scripting

Calculate total value from a row

HI I have a file # cat marks.txt MARKS LIST 2013 Name english french chinese latin total_marks wer 34 45 67 23 wqa 12 39 10 56 wsy 23 90 23 78 Now i need to find the total marks of each student using... (11 Replies)
Discussion started by: Priya Amaresh
11 Replies

7. Shell Programming and Scripting

Calculate the total

Hi All , I have the following script as below , I tried to modify to meet the requirement , could someone help ? very thanks ================================================================================================ while read STR NAME; do Total=0 MyString="$STR" GetData () {... (18 Replies)
Discussion started by: ust3
18 Replies

8. Shell Programming and Scripting

awk to calculate total and percent off field in file

Trying to use awk to print the lines in file that have either REF or SNV in $3, add a header line, sort by $4 in numerical order. The below code does that already, but where I am stuck is on the last part where the total lines are counted and printed under Total_Targets, under Targets_less_than is... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. Shell Programming and Scripting

Calculate total memory using free -m

Hi I am trying to calculate memory used by Linux System free -m total used free shared buffers cached Mem: 32109 31010 1099 0 3600 7287 -/+ buffers/cache: 20121 11987 Swap: 10239 1282 8957 Now according to my requirement Im calculating memory using below cmd free -m | awk 'NR==3{printf... (2 Replies)
Discussion started by: sam@sam
2 Replies
NETSED(1)							      NetSED								 NETSED(1)

NAME
netsed - a network stream editor. SYNOPSIS
netsed {proto} {lport} {rhost} {rport} {rule} [rule ...] DESCRIPTION
netsed is a small and handy utility to alter, in real time, the contents of packets forwarded in a network stream, or in a datagram connection. When called with a set of replacement rules, these rules are tested for applicability to each packet entering in either direction. ARGUMENTS
proto Determines the protocol for the desired connection: "tcp", "TCP", "udp", or "UDP". lport The local listening port for the connection. A service name, or a numerical port value, is acceptable. rhost The remote host with whom the connection is desired. Resolvable host names and IPv4/IPv6 addresses are equally usable. As a special case, assigning "0" to rhost will insert the kernel's knowledge of the targeted host address, in a situation where a netfilter rule is redirecting traffic. This happens when running a transparent proxy service. rport The remote port to connect to. A service name, or a numerical port value, is acceptable. Also here a value "0" will be acceptable to arrange a transparent proxy service, as the kernel's tracking will provide the intended remote port number. rule At least one replacement rule is mandatory. The general syntax for this is: s/pat1/pat2[/num] The effect is to replace the text that matches pat1 with the expansion of pat2. The optional parameter num is a numerical value limiting the maximal number of times the rule can be applied. One could say that the rule expires after num occurrences. The rules are applied in succession to all passing packets, flowing in either direction. As soon as a rule has been expired, it is removed from the collection of active rules for the current connection. Observe that any counter is started as the connection is initiated, running as long as the connection is alive. This holds directly for TCP connections, whereas for UDP a connection is considered to consist of incoming data on fixed address and fixed port together with any response from a remote server. When no datagrams have been transmitted for a period of 30 seconds, the UPD connection is seen as closed. A single rule is limited to act on individual packets; a pattern can not match across packet boundaries. Using HTTP-like escape sequences for hexadecimal values, all eight-bit characters are viable in the patterns. Thus the standard character pair CRNL would code as "%0a%0d". In a pattern, the percentage sign itself must be escaped by duplication. Thus a string "%%" is interpreted in a pattern as a literal percentage sign. EXAMPLES
A handful replacement rules are handy as examples. s/andrew/mike Replace every occurrence of the string "andrew" with "mike", in every passing packet. s/andrew/mike/1 Replace only the first occurrence of the string "andrew" for "mike" in each packet. Any repetition is unaltered, unless a further rule specifies some replacement. s/andrew/mike%00%00 Replace in each packet every occurrence of the string "andrew" with "mikex00x00" . The padding with two null bytes ensures an unaltered packet length, which might be essential at times. s/%%/%2f/20 Replace the first twenty occurrences of the percentage character '%' with slashes '/'. AUTHOR
This text was initially compiled by Mats Erik Andersson as a Docbook source from the usage printout. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Public License, version 2, or of a later version. COPYRIGHT
Copyright (C) 2010 Mats Erik Andersson NetSED 1.00b June 19th, 2011 NETSED(1)
All times are GMT -4. The time now is 04:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy