Sponsored Content
Top Forums Shell Programming and Scripting Sum specified values (columns) per row Post 302898168 by vgersh99 on Saturday 19th of April 2014 01:19:01 PM
Old 04-19-2014
sorry, a tiny boo-boo:
Code:
{
        f=0
        for(i=4;i<=NF;i++) {
                n=split($i,a,":")
                s=0
                for(j=1;j<n;j++) s+=a[j]
                  if (s>=8)
                    f++
        }
}
f==(NF-3)

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sum of values coming in a row

Hi, my requirement is to sum values in a row. eg: input is: sum,value1,value2,value3,.....,value N Required Output: sum,<summation of N values> Please help me... (5 Replies)
Discussion started by: MrGopal666
5 Replies

2. Shell Programming and Scripting

Sum up values of columns in 4 files using shell script

I am new to shell script.I have records like below in 4 different files which have about 10000 records each, all records unique and sorted based on column 2. 1 2 3 4 5 6 --------------------------- SR|1010478|000044590|1|0|0| SR|1014759|000105790|1|0|0| SR|1016609|000108901|1|0|0|... (2 Replies)
Discussion started by: reach.sree@gmai
2 Replies

3. UNIX for Dummies Questions & Answers

Select 2 columns and transpose row by row

Hi, I have a tab-delimited file as follows: 1 1 2 2 3 3 4 4 a a b b c c d d 5 5 6 6 7 7 8 8 e e f f g g h h 9 9 10 10 11 11 12 12 i i j j k k l l 13 13 14 14 15 15 16 16 m m n n o o p p The output I need is: 1 1 a a 5 5 e e 9 9 i i 13... (5 Replies)
Discussion started by: mvaishnav
5 Replies

4. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

5. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

6. Shell Programming and Scripting

Add sum of columns and max as new row

Hi, I am a new bie i need some help with respect to shell onliner; I have data in following format Name FromDate UntilDate Active Changed Touched Test 28-03-2013 28-03-2013 1 0.6667 100 Test2 28-03-2013 03-04-2013 ... (1 Reply)
Discussion started by: gangaraju6
1 Replies

7. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies

8. UNIX for Beginners Questions & Answers

Group by columns and add sum in new columns

Dear Experts, I have input file which is comma separated, has 4 columns like below, BRAND,COUNTRY,MODEL,COUNT NIKE,USA,DUMMY,5 NIKE,USA,ORIGINAL,10 PUMA,FRANCE,DUMMY,20 PUMA,FRANCE,ORIGINAL,15 ADIDAS,ITALY,DUMMY,50 ADIDAS,ITALY,ORIGINAL,50 SPIKE,CHINA,DUMMY,1O And expected output add... (2 Replies)
Discussion started by: ricky1991
2 Replies

9. Shell Programming and Scripting

Do replace operation and awk to sum multiple columns if another column has duplicate values

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (12 Replies)
Discussion started by: as7951
12 Replies

10. UNIX for Beginners Questions & Answers

Copy columns from one file into another and get sum of column values and row count

I have a file abc.csv, from which I need column 24(PurchaseOrder_TotalCost) to get the sum_of_amounts with date and row count into another file say output.csv abc.csv- UTF-8,,,,,,,,,,,,,,,,,,,,,,,,, ... (6 Replies)
Discussion started by: Tahir_M
6 Replies
Moose::Meta::Attribute::Native::Trait::Array(3) 	User Contributed Perl Documentation	   Moose::Meta::Attribute::Native::Trait::Array(3)

NAME
Moose::Meta::Attribute::Native::Trait::Array - Helper trait for ArrayRef attributes VERSION
version 2.1202 SYNOPSIS
package Stuff; use Moose; has 'options' => ( traits => ['Array'], is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] }, handles => { all_options => 'elements', add_option => 'push', map_options => 'map', filter_options => 'grep', find_option => 'first', get_option => 'get', join_options => 'join', count_options => 'count', has_options => 'count', has_no_options => 'is_empty', sorted_options => 'sort', }, ); no Moose; 1; DESCRIPTION
This trait provides native delegation methods for array references. DEFAULT TYPE
If you don't provide an "isa" value for your attribute, it will default to "ArrayRef". PROVIDED METHODS
o count Returns the number of elements in the array. $stuff = Stuff->new; $stuff->options( [ "foo", "bar", "baz", "boo" ] ); print $stuff->count_options; # prints 4 This method does not accept any arguments. o is_empty Returns a boolean value that is true when the array has no elements. $stuff->has_no_options ? die "No options! " : print "Good boy. "; This method does not accept any arguments. o elements Returns all of the elements of the array as an array (not an array reference). my @option = $stuff->all_options; print "@options "; # prints "foo bar baz boo" This method does not accept any arguments. o get($index) Returns an element of the array by its index. You can also use negative index numbers, just as with Perl's core array handling. my $option = $stuff->get_option(1); print "$option "; # prints "bar" If the specified element does not exist, this will return "undef". This method accepts just one argument. o pop Just like Perl's builtin "pop". This method does not accept any arguments. o push($value1, $value2, value3 ...) Just like Perl's builtin "push". Returns the number of elements in the new array. This method accepts any number of arguments. o shift Just like Perl's builtin "shift". This method does not accept any arguments. o unshift($value1, $value2, value3 ...) Just like Perl's builtin "unshift". Returns the number of elements in the new array. This method accepts any number of arguments. o splice($offset, $length, @values) Just like Perl's builtin "splice". In scalar context, this returns the last element removed, or "undef" if no elements were removed. In list context, this returns all the elements removed from the array. This method requires at least one argument. o first( sub { ... } ) This method returns the first matching item in the array, just like List::Util's "first" function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. Each list element will be available to the sub in $_. my $found = $stuff->find_option( sub {/^b/} ); print "$found "; # prints "bar" This method requires a single argument. o first_index( sub { ... } ) This method returns the index of the first matching item in the array, just like List::MoreUtils's "first_index" function. The matching is done with a subroutine reference you pass to this method. The subroutine will be called against each element in the array until one matches or all elements have been checked. Each list element will be available to the sub in $_. This method requires a single argument. o grep( sub { ... } ) This method returns every element matching a given criteria, just like Perl's core "grep" function. This method requires a subroutine which implements the matching logic; each list element will be available to the sub in $_. my @found = $stuff->filter_options( sub {/^b/} ); print "@found "; # prints "bar baz boo" This method requires a single argument. o map( sub { ... } ) This method transforms every element in the array and returns a new array, just like Perl's core "map" function. This method requires a subroutine which implements the transformation; each list element will be available to the sub in $_. my @mod_options = $stuff->map_options( sub { $_ . "-tag" } ); print "@mod_options "; # prints "foo-tag bar-tag baz-tag boo-tag" This method requires a single argument. o reduce( sub { ... } ) This method turns an array into a single value, by passing a function the value so far and the next value in the array, just like List::Util's "reduce" function. The reducing is done with a subroutine reference you pass to this method; each list element will be available to the sub in $_. my $found = $stuff->reduce_options( sub { $_[0] . $_[1] } ); print "$found "; # prints "foobarbazboo" This method requires a single argument. o sort o sort( sub { ... } ) Returns the elements of the array in sorted order. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b in this subroutine, you will need to use $_[0] and $_[1]. # ascending ASCIIbetical my @sorted = $stuff->sort_options(); # Descending alphabetical order my @sorted_options = $stuff->sort_options( sub { lc $_[1] cmp lc $_[0] } ); print "@sorted_options "; # prints "foo boo baz bar" This method accepts a single argument. o sort_in_place o sort_in_place( sub { ... } ) Sorts the array in place, modifying the value of the attribute. You can provide an optional subroutine reference to sort with (as you can with Perl's core "sort" function). However, instead of using $a and $b, you will need to use $_[0] and $_[1] instead. This method does not define a return value. This method accepts a single argument. o shuffle Returns the elements of the array in random order, like "shuffle" from List::Util. This method does not accept any arguments. o uniq Returns the array with all duplicate elements removed, like "uniq" from List::MoreUtils. This method does not accept any arguments. o join($str) Joins every element of the array using the separator given as argument, just like Perl's core "join" function. my $joined = $stuff->join_options(':'); print "$joined "; # prints "foo:bar:baz:boo" This method requires a single argument. o set($index, $value) Given an index and a value, sets the specified array element's value. This method returns the value at $index after the set. This method requires two arguments. o delete($index) Removes the element at the given index from the array. This method returns the deleted value. Note that if no value exists, it will return "undef". This method requires one argument. o insert($index, $value) Inserts a new element into the array at the given index. This method returns the new value at $index. This method requires two arguments. o clear Empties the entire array, like "@array = ()". This method does not define a return value. This method does not accept any arguments. o accessor($index) o accessor($index, $value) This method provides a get/set accessor for the array, based on array indexes. If passed one argument, it returns the value at the specified index. If passed two arguments, it sets the value of the specified index. When called as a setter, this method returns the new value at $index. This method accepts one or two arguments. o natatime($n) o natatime($n, $code) This method returns an iterator which, on each call, returns $n more items from the array, in order, like "natatime" from List::MoreUtils. If you pass a coderef as the second argument, then this code ref will be called on each group of $n elements in the array until the array is exhausted. This method accepts one or two arguments. o shallow_clone This method returns a shallow clone of the array reference. The return value is a reference to a new array with the same elements. It is shallow because any elements that were references in the original will be the same references in the clone. BUGS
See "BUGS" in Moose for details on reporting bugs. AUTHORS
o Stevan Little <stevan.little@iinteractive.com> o Dave Rolsky <autarch@urth.org> o Jesse Luehrs <doy@tozt.net> o Shawn M Moore <code@sartak.org> o XXXX XXX'XX (Yuval Kogman) <nothingmuch@woobling.org> o Karen Etheridge <ether@cpan.org> o Florian Ragwitz <rafl@debian.org> o Hans Dieter Pearcey <hdp@weftsoar.net> o Chris Prather <chris@prather.org> o Matt S Trout <mst@shadowcat.co.uk> COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2014-01-19 Moose::Meta::Attribute::Native::Trait::Array(3)
All times are GMT -4. The time now is 09:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy