Sponsored Content
Full Discussion: Adding matching field
Top Forums Shell Programming and Scripting Adding matching field Post 302588114 by vgersh99 on Friday 6th of January 2012 06:01:42 PM
Old 01-06-2012
Code:
nawk -F, '{a[$1]+=$2;fld=NF}END{for(i in a) {printf("%s%c%s",i,OFS,a[i]);$(fld-2)=OFS;print}}' OFS=, myFile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding field values if field matches

hi i have file as below , i want to add duplicate records like bell_bb to one record with valuve as 15 ( addition of both ) any oneline awk script to achive this ? header 0 CAMPAIGN_NAME 1 Bell_BB 14 Bell_MONTHLY 803 SOLO_UNBEATABLE 644 Bell_BB 1 Bell_MONTHLY 25 SOLO_UNBEATABLE... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

2. Shell Programming and Scripting

Need some help matching a field in one file with a field in another

One file (file1) is as such: Abc.txt 1.1 1.3 Abc_v2.txt 1.1 1.4 Tree.txt 1.3 1.4 Grass.txt 1.3 4.5 The other (file2): Horse.txt 1.1 ref23232 Abc.txt 1.1 1.2 ref 3232-3232 1.3 ref 3232-3232 Plane.txt 1.1 1.2 ref 3232-3232 1.3 ref 3232-3232 1.4 Tree.txt 1.3 ref 3232-3232 1.4... (5 Replies)
Discussion started by: linuxkid
5 Replies

3. Shell Programming and Scripting

Field matching between 2 files

Okay so I'm pretty new to scripting therefore this problem seems pretty tough. I have a main file that has a column of IP addresses and I have to compare it with 3 separate files that also have IP address columns. These 3 files are automatically generated from 3 different servers. Each time... (2 Replies)
Discussion started by: Spunkerspawn
2 Replies

4. Shell Programming and Scripting

Adding new field

Hello, I have a main file with IP addresses like this: Erisim var,100,172.17.241.5,4006,60,IS0799,TCP/IP Erisim var,1003,172.17.140.4,4004,60,IS2156,TCP/IP Erisim var,1004,172.17.140.5,4002,60,IS2636,TCP/IP Erisim var,1005,172.17.140.5,4004,60,IS2436,TCP/IP Erisim... (8 Replies)
Discussion started by: Spunkerspawn
8 Replies

5. Shell Programming and Scripting

Adding total of first field for each number in the second field

Dears, I need a script or command which can find the unique number from the second filed and against that number it adds the total of first field . 17215630 , 0 907043 ,1 201050 ,10 394149 ,4 1964 ,9 17215630, 0 907043 ,1 201050, 10 394149 ,4 1964 ,9 1234234, 55 23 ,100 33 ,67 ... (2 Replies)
Discussion started by: shary
2 Replies

6. Shell Programming and Scripting

Adding numbers matching with words

Hi All, I have a file which looks like this: abc 1 abc 2 abc 3 abc 4 abc 5 bcd 1 bcd 3 bcd 3 bcd 5 cde 7 This file is just a miniature version of what I really have. Original file is some 1 million lines long. I have tried to come up with the code for what I wish to accomplish... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

7. UNIX for Dummies Questions & Answers

Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern: The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off: sed 'Wf a\'/n'/g' Basically, I want to add a new line after occurrence of Wf. After the line Wf... (5 Replies)
Discussion started by: MIA651
5 Replies

8. Shell Programming and Scripting

Awk: adding fields after matching $1

Dear AWK-experts! I did get stuck in the task of combining files after matching fields, so I'm still awkward with learning AWK. There are 2 files: one containing 3 columns with ID, coding status, and score for long noncoding RNAs: file1 (1.txt) (>5000 lines) ... (12 Replies)
Discussion started by: kben
12 Replies

9. Shell Programming and Scripting

Adding field to file

Hi I have file as given below 040|14300|40.0|563000 042|13200000|40.0 041|100|40.0 043|10000|40.0 045|102|40.0 I want to check if field 4 is null then I have to place | in position 4. result set should be 040|14300|40.0|563000 042|13200000|40.0| 041|100|40.0| 043|10000|40.0|... (9 Replies)
Discussion started by: shabeena
9 Replies

10. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies
SQL::Translator::Diff(3pm)				User Contributed Perl Documentation				SQL::Translator::Diff(3pm)

NAME
SQL::Translator::Diff - determine differences between two schemas DESCRIPTION
Takes two input SQL::Translator::Schemas (or SQL files) and produces ALTER statments to make them the same SNYOPSIS
Simplest usage: use SQL::Translator::Diff; my $sql = SQL::Translator::Diff::schema_diff($source_schema, 'MySQL', $target_schema, 'MySQL', $options_hash) OO usage: use SQL::Translator::Diff; my $diff = SQL::Translator::Diff->new({ output_db => 'MySQL', source_schema => $source_schema, target_schema => $target_schema, %$options_hash, })->compute_differences->produce_diff_sql; OPTIONS
ignore_index_names Match indexes based on types and fields, ignoring name. ignore_constraint_names Match constrains based on types, fields and tables, ignoring name. output_db Which producer to use to produce the output. case_insensitive Ignore case of table, field, index and constraint names when comparing no_batch_alters Produce each alter as a distinct "ALTER TABLE" statement even if the producer supports the ability to do all alters for a table as one statement. ignore_missing_methods If the diff would need a method that is missing from the producer, just emit a comment showing the method is missing, rather than dieing with an error PRODUCER FUNCTIONS
The following producer functions should be implemented for completeness. If any of them are needed for a given diff, but not found, an error will be thrown. o "alter_create_constraint($con)" o "alter_drop_constraint($con)" o "alter_create_index($idx)" o "alter_drop_index($idx)" o "add_field($fld)" o "alter_field($old_fld, $new_fld)" o "rename_field($old_fld, $new_fld)" o "drop_field($fld)" o "alter_table($table)" o "drop_table($table)" o "rename_table($old_table, $new_table)" (optional) o "batch_alter_table($table, $hash)" (optional) If the producer supports "batch_alter_table", it will be called with the table to alter and a hash, the keys of which will be the method names listed above; values will be arrays of fields or constraints to operate on. In the case of the field functions that take two arguments this will appear as a hash. I.e. the hash might look something like the following: { alter_create_constraint => [ $constraint1, $constraint2 ], add_field => [ $field ], alter_field => [ [$old_field, $new_field] ] } o "preprocess_schema($class, $schema)" (optional) "preprocess_schema" is called by the Diff code to allow the producer to normalize any data it needs to first. For example, the MySQL producer uses this method to ensure that FK contraint names are unique. Basicaly any changes that need to be made to produce the SQL file for the schema should be done here, so that a diff between a parsed SQL file and (say) a parsed DBIx::Class::Schema object will be sane. (As an aside, DBIx::Class, for instance, uses the presence of a "preprocess_schema" function on the producer to know that it can diff between the previous SQL file and its own internal representation. Without this method on th producer it will diff the two SQL files which is slower, but known to work better on old-style producers.) AUTHOR
Original Author(s) unknown. Refactor/re-write and more comprehensive tests by Ash Berlin "ash@cpan.org". Redevelopment sponsored by Takkle Inc. perl v5.14.2 2012-05-01 SQL::Translator::Diff(3pm)
All times are GMT -4. The time now is 01:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy