Sponsored Content
Top Forums Shell Programming and Scripting Adding values of a column based on another column Post 302876266 by RavinderSingh13 on Friday 22nd of November 2013 01:50:57 PM
Old 11-22-2013
Hello Homa,

this following code may help.

Code:
awk '
                        $1 != first_value {
                        print first_value" "total_value;
                        first_value=$1;
                        totat_value=$6;
        total_value=0;
        }
        {
        total_value=total_value+$6
                }' file_name



Thanks,
R. Singh
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding a column to a text based on file name

Dear all, Does anyone know how I could to add a column of numbers (1s, or 2s, or..., or 6s) to two-column text files (tab-delimited), where the specific number to be added varies as a function of the file naming? Currently, each of my text files has two columns, so the column with the... (12 Replies)
Discussion started by: rlapate
12 Replies

2. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

3. Shell Programming and Scripting

problem while adding column values in awk

Hi, I have a file "input.txt" with the following content : 5312,0,,,1,8,141.2,20090727 3714,0,,,1,8,285.87,20090727 5426,0,,,1,8,3.9,20090727 3871,0,,,1,8,30.4,20090727 9071,0,,,1,8,146.2,20090727 5141,0,,,1,8,2.8,20090727 0460,0,,,1,8,-0.1,20090727 7918,0,,,1,8,-0.1,20090727... (3 Replies)
Discussion started by: valokv
3 Replies

4. Shell Programming and Scripting

How to averaging column based on first column values

Hello I have file that consist of 2 columns of millions of entries timestamp and throughput I want to find the average (throughput ) for each equal timestamp before change it to proper format e.g : i want to average 2 coloumnd fot all 1308154800 values in column 1 and then print... (4 Replies)
Discussion started by: aadel
4 Replies

5. UNIX for Dummies Questions & Answers

Adding column with values

Dear all, I need your help for my question please I have without header (space separated) and need to add two colomns at the beginning with values my file look like : rs1 a t 0.6 rs2 a c 0.3 rs3 t g 0.8 I need to a new file like: 1 100 rs1 a t 0.6 1 100 rs2 a c 0.3 1 100 rs3 t g... (3 Replies)
Discussion started by: biopsy
3 Replies

6. Shell Programming and Scripting

Adding column values in a file

Hi, I am having a file in the following format. for aaaa 1111 1234 2222 3434 for bbbb 1111 3434.343 2222 2343 for cccc 3333 2343.343 4444 89000 for dddd 1111 5678.343 2222 890.3 aaaa 2343.343 bbbb 34343.343 (5 Replies)
Discussion started by: jpkumar10
5 Replies

7. Shell Programming and Scripting

Adding Column Values Using Pattern Match

Hi All, I have a file with data as below: A,FILE1_MYFILE_20130309_1038,80,25.60 B,FILE1_MYFILE_20130309_1038,24290,18543.38 C,FILE1_dsc_dlk_MYFILE_20130309_1038,3,10.10 A,FILE2_MYFILE_20130310_1039,85,110.10 B,FILE2_MYFILE_20130310_1039,10,12.10... (10 Replies)
Discussion started by: angshuman
10 Replies

8. Shell Programming and Scripting

Adding of two column values

Hi cat /tmp/xx.txt 1 4 1 5 1 6 2 1 2 1 2 1 i want to add the values of 2nd column resepect to 1st column values..for 1 in 1st column i need sum of all the values in 2nd column ..pls tell me hw to do it?? (8 Replies)
Discussion started by: Aditya.Gurgaon
8 Replies

9. Shell Programming and Scripting

Sum column values based in common identifier in 1st column.

Hi, I have a table to be imported for R as matrix or data.frame but I first need to edit it because I've got several lines with the same identifier (1st column), so I want to sum the each column (2nd -nth) of each identifier (1st column) The input is for example, after sorted: K00001 1 1 4 3... (8 Replies)
Discussion started by: sargotrons
8 Replies

10. Shell Programming and Scripting

Concatenate values in the first column based on the second column.

I have a file (myfile.txt) with contents like this: 1.txt apple is 3.txt apple is 5.txt apple is 2.txt apple is a 7.txt apple is a 8.txt apple is a fruit 4.txt orange not a fruit 6.txt zero isThe above file is already sorted using this command: sort -k2 myfile.txtMy objective is to get... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies
Data::Phrasebook::Loader::YAML(3pm)			User Contributed Perl Documentation		       Data::Phrasebook::Loader::YAML(3pm)

NAME
Data::Phrasebook::Loader::YAML - Absract your phrases with YAML. SYNOPSIS
use Data::Phrasebook; my $q = Data::Phrasebook->new( class => 'Fnerk', loader => 'YAML', file => 'phrases.yaml', ); $q->delimiters( qr{ [% s* (w+) s* %] }x ); my $phrase = $q->fetch($keyword); ABSTRACT
This module provides a loader class for phrasebook implementations using YAML. DESCRIPTION
This class loader implements phrasebook patterns using YAML. Phrases can be contained within one or more dictionaries, with each phrase accessible via a unique key. Phrases may contain placeholders, please see Data::Phrasebook for an explanation of how to use these. Groups of phrases are kept in a dictionary. In this implementation a single file is one complete dictionary. An example YAML file: --- foo: > Welcome to [% my %] world. It is a nice [%place %]. Within the phrase text placeholders can be used, which are then replaced with the appropriate values once the get() method is called. The default style of placeholders can be altered using the delimiters() method. INHERITANCE
Data::Phrasebook::Loader::YAML inherits from the base class Data::Phrasebook::Loader::Base. See that module for other available methods and documentation. METHODS
load Given a "file", load it. "file" must contain a YAML map. $loader->load( $file, @dict ); This method is used internally by Data::Phrasebook::Generic's "data" method, to initialise the data store. It must take a "file" (be it a scalar, or something more complex) and return a handle. The "dict" is optional, should you wish to use the dictionary support. get Returns the phrase stored in the phrasebook, for a given keyword. my $value = $loader->get( $key ); If one or more named dictionaries have been previously selected, they will be searched in order, followed by the default dictionary. The first hit on "key" will be returned, otherwise "undef" is returned. dicts Returns the list of dictionaries available. my @dicts = $loader->dicts(); This is the list of all dictionaries available in the source file. If multiple dictionaries are not being used, then an empty list will be returned. keywords Returns the list of keywords available. List is lexically sorted. my @keywords = $loader->keywords( $dict ); If one or more named dictionaries have been previously selected, they will be farmed for keywords, followed by the default dictionary. The "dict" argument is optional, and may be used to override the search to a single named dictionary, or a list of dictionaries if passed by reference, plus the default dictionary of course. To find all available keywords in all available dictionaries, use the following: $loader->keywords( [ $loader->dicts ] ); set_default If a requested phrase is not found in the named dictionary an attempt is made to find it in the default dictionary. Data::Phrasebook loaders normally use the first dictionary in the phrasebook as the default, but as mentioned in "DICTIONARY SUPPORT" this does not make sense because the dictionaries in YAML phrasebooks are not ordered. To override the automatically selected default dictionary use this method, and pass it a "default_dictionary_name". This value is only reset at phrasebook load time, so you'll probably need to trigger a reload: $q->loader->set_default( $default_dictionary_name ); $q->loader->load( $file ); To reset the loader's behaviour to automatic default dictionary selection, pass this method an undefined value, and then reload. DICTIONARY SUPPORT
This loader supports the use of dictionaries, as well as multiple dictionaries with a search order. If you are unfamiliar with these features, see Data::Phrasebook for more information. Source data format for a single unnamed dictionary is a YAML stream that has as its root node an anonymous hash, like so: --- first_key: first_value second_key: second_value In this case, specifying one or more named dictionaries will have no effect. The single dictionary that comprises the YAML file will take the place of your default dictionary, so will always be searched. To override this behaviour use the "set_default" object method. Multiple dictionaries must be specified using a two-level hash system, where the root node of your YAML file is an anonymous hash containing dictionary names, and the values of those hash keys are further anonymous hashes containing the dictionary contents. Here is an example: --- dict_one: first_key: first_value second_key: second_value dict_two: first_key: first_value second_key: second_value If you use any other structure for your YAML dictionary files, the result is uncertain, and this loader module is very likely to crash your program. If a requested phrase is not found in the named dictionary an attempt is made to find it in the default dictionary. Data::Phrasebook loaders normally use the first dictionary in the phrasebook as the default, but this does not make sense because YAML phrasebook files contain an unordered hash of dictionaries. This loader will therefore select the first dictionary from the list of lexically sorted dictionary names to be the default. To override this behaviour use the "set_default" object method. Alternatively, just include a dictionary that is guaranteed to be selected for the default (e.g. "0000default"); it need not contain any keys. SEE ALSO
Data::Phrasebook, Data::Phrasebook::Loader. BUGS, PATCHES &; FIXES There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties, that is not explained within the POD documentation, please send an email to barbie@cpan.org or submit a bug to the RT system (http://rt.cpan.org/). However, it would help greatly if you are able to pinpoint problems or even supply a patch. Fixes are dependent upon their severity and my availability. Should a fix not be forthcoming, please feel free to (politely) remind me. DSLIP
b - Beta testing d - Developer p - Perl-only O - Object oriented p - Standard-Perl: user may choose between GPL and Artistic AUTHOR
Original author: Iain Campbell Truskett (16.07.1979 - 29.12.2003) Maintainer: Barbie <barbie@cpan.org> since January 2004. for Miss Barbell Productions <http://www.missbarbell.co.uk>. COPYRIGHT AND LICENSE
Copyright (C) 2003 Iain Truskett. All rights reserved. Copyright (C) 2004-2007 Barbie for Miss Barbell Productions. All Rights Reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the licenses can be found in the Artistic and COPYING files included with this module, or in perlartistic and perlgpl in Perl 5.8.1 or later. perl v5.10.1 2010-10-12 Data::Phrasebook::Loader::YAML(3pm)
All times are GMT -4. The time now is 01:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy