Sponsored Content
Top Forums Shell Programming and Scripting Change numbers in a file, incrementing them Post 302641647 by neutronscott on Wednesday 16th of May 2012 10:58:02 AM
Old 05-16-2012
if all you have is key:val then awk is good at math:

Code:
$ printf '%s\n' key1:431 key2:159 key3:998 | awk -F: '{print $1 FS 3+$2}'
key1:434
key2:162
key3:1001

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Port incrementing using one file

Hi I wrote this script with the help of you guyz.My next challenge is to increment the port using single file.So far iam using this code to increment hp1 and hp2 .To increment port numbers, iam using two different files (.default_port_hp1 and .default_port_hp2).The challenge for me is to use... (0 Replies)
Discussion started by: coolkid
0 Replies

2. UNIX for Dummies Questions & Answers

Incrementing the New File Version Number

Hello All, In the below script i am trying to check and list the file names, get the last file with highest version number and then increment the version number when i create another file. Example: file1 is COBANK_v1.xml and file2 i want to put it as COBANK_v2.xml, to achieve this i am using awk... (15 Replies)
Discussion started by: Ariean
15 Replies

3. Shell Programming and Scripting

Change numbers in flat file

Hi, I have some datatexts with values and I want to replace only the values of the first file with the result of array loaded in one variable. Also I want the operation difference with the original value replaced and only replace the new value not the character format of the file. Some Idea?... (24 Replies)
Discussion started by: faka
24 Replies

4. Shell Programming and Scripting

Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test': I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working: cat test |... (3 Replies)
Discussion started by: crunchgargoyle
3 Replies

5. Shell Programming and Scripting

Adding (as in arithmetic) to numbers in columns in file, and writing new file with new numbers

Hi again. Sorry for all the questions — I've tried to do all this myself but I'm just not good enough yet, and the help I've received so far from bartus11 has been absolutely invaluable. Hopefully this will be the last bit of file manipulation I need to do. I have a file which is formatted as... (4 Replies)
Discussion started by: crunchgargoyle
4 Replies

6. Shell Programming and Scripting

Change the numbers

Hi friends, i need a command which can be used to change the values in file. I have file which contain some values. Data_Center_costing=XXXX Financial_loss=XXXX operational_cost=XXX I am not aware about the values of XXXX, They may be 4 digit or less/more than that. but i need these... (12 Replies)
Discussion started by: Nakul_sh
12 Replies

7. Shell Programming and Scripting

Change numbers

Hallo This is the content of the file 3 4 5 6 7 8 9 10 11 12 And I want the following output 1 2 3 4 5 6 7 (4 Replies)
Discussion started by: thailand
4 Replies

8. Shell Programming and Scripting

Hint needed for incrementing numbers

Hi All Been trying to get something working but having some trouble in unix bash or ksh scripting. Im trying to increment once a condition has been met Say I have a file that contains: apple orange banana grapes dates kiwi What im after is once a counter has reached every second... (3 Replies)
Discussion started by: chandika_diran
3 Replies

9. UNIX for Advanced & Expert Users

Add an incrementing identity column to a file

Two questions: 1) Is there a way to create a new column (i.e. ID) to an existing file containing data and the new column ID populate as an auto incrementing number? for example: (Current file has headers and is PIPE delimited.) **data looks like this** "COL1"|"COL2"|"COL3"|"COL4"|"COL5"... (4 Replies)
Discussion started by: timlisa20
4 Replies

10. UNIX for Beginners Questions & Answers

Incrementing the New File Version Number

Hi, This is my first post here. I am using cygwin on Windows 7. I am starting with a data file with filename "name_1.ext", like "20180831_snapgenotypes_1.csv". The "_1" before ".ext" is a version number. Integers (0-99) are sufficient. They don't have to be like "1.0.0". The filename may... (2 Replies)
Discussion started by: minimalist
2 Replies
MouseX::NativeTraits::HashRef(3pm)			User Contributed Perl Documentation			MouseX::NativeTraits::HashRef(3pm)

NAME
MouseX::NativeTraits::HashRef - Helper trait for HashRef attributes SYNOPSIS
package Stuff; use Mouse; has 'options' => ( traits => ['Hash'], is => 'ro', isa => 'HashRef[Str]', default => sub { {} }, handles => { set_option => 'set', get_option => 'get', has_no_options => 'is_empty', num_options => 'count', delete_option => 'delete', pairs => 'kv', }, ); DESCRIPTION
This module provides a Hash attribute which provides a number of hash-like operations. PROVIDED METHODS
These methods are implemented in MouseX::NativeTraits::MethodProvider::HashRef. get($key, $key2, $key3...) Returns values from the hash. In list context return a list of values in the hash for the given keys. In scalar context returns the value for the last key specified. set($key => $value, $key2 => $value2...) Sets the elements in the hash to the given values. delete($key, $key2, $key3...) Removes the elements with the given keys. exists($key) Returns true if the given key is present in the hash. defined($key) Returns true if the value of a given key is defined. keys Returns the list of keys in the hash. sorted_keys Returns the list of sorted keys in the hash. values Returns the list of values in the hash. kv Returns the key/value pairs in the hash as an array of array references. for my $pair ( $object->options->pairs ) { print "$pair->[0] = $pair->[1] "; } elements Returns the key/value pairs in the hash as a flattened list. clear Resets the hash to an empty value, like "%hash = ()". count Returns the number of elements in the hash. Also useful for not empty: "has_options => 'count'". is_empty If the hash is populated, returns false. Otherwise, returns true. accessor If passed one argument, returns the value of the specified key. If passed two arguments, sets the value of the specified key. METHODS
meta method_provider_class helper_type SEE ALSO
MouseX::NativeTraits perl v5.14.2 2011-12-04 MouseX::NativeTraits::HashRef(3pm)
All times are GMT -4. The time now is 03:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy