Sponsored Content
Top Forums Shell Programming and Scripting Adding Column Values Using Pattern Match Post 302784303 by guruprasadpr on Friday 22nd of March 2013 01:42:53 AM
Old 03-22-2013
One way:

Code:
awk -F, '{x=$2;sub(/_.*/,"",x);if(!a[x])a[x]=$2;b[x]+=$3;}END{for (i in a)print a[i]","b[i];}' file

Guru.
 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Need help in adding the column to set of lines that match the certain criteria

Hi, I need help to add a certain values to end of each line in the same file. Here is my input file name:aaa id :123 salary job qulification name:bbb id :124 salary job qulification name:ccc id :345 salary job qulification (2 Replies)
Discussion started by: jpkumar10
2 Replies

3. 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

4. Shell Programming and Scripting

Compare values for a pattern match and execute script

Here in the input file 23:59:13,devicename,21,server1,700 23:59:13,devicename,22,server2,200 23:59:13,devicename,23,server3,200 23:59:13,devicename,24,server4,200 23:59:13,devicename,25,server5,200 23:59:13,devicename,26,server6,200 23:59:13,devicename,27,server7,200... (6 Replies)
Discussion started by: necro98
6 Replies

5. 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

6. 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

7. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

Adding values of a column based on another column

Hello, I have a data such as this: ENSGALG00000000189 329 G A 4 2 0 ENSGALG00000000189 518 T C 5 1 0 ENSGALG00000000189 1104 G A 5 1 0 ENSGALG00000000187 3687 G T 5 1 0 ENSGALG00000000187 4533 A T 4 2 0 ENSGALG00000000233 5811 T C 4 2 0 ENSGALG00000000233 5998 C A 5 1 0 I want to... (3 Replies)
Discussion started by: Homa
3 Replies

9. UNIX for Dummies Questions & Answers

Match sum of values in each column with the corresponding column value present in trailer record

Hi All, I have a requirement where I need to find sum of values from column D through O present in a CSV file and check whether the sum of each Individual column matches with the value present for that corresponding column present in the trailer record. For example, let's assume for column D... (9 Replies)
Discussion started by: tpk
9 Replies

10. Shell Programming and Scripting

If pattern match in other column, modify column 3.

My command sed will modify everything in column 3 if i will use the command below. I want to search for a pattern then modify everything in column 3. sed -i 's/\|165\|/server1/g' file.txt Input: 01-31-2019 19:14:05|device|165|1548962040165|5c5348f9-0804-1111|file_attach|7271|587|smtp|... (6 Replies)
Discussion started by: invinzin21
6 Replies
mlib_ImageNormCrossCorrel(3MLIB)										  mlib_ImageNormCrossCorrel(3MLIB)

NAME
mlib_ImageNormCrossCorrel - normalized cross correlation SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageNormCrossCorrel(mlib_d64 *correl, const mlib_image *img1, const mlib_image *img2, const mlib_d64 *mean2, const mlib_d64 *sdev2); The mlib_ImageNormCrossCorrel() function computes the normalized cross-correlation coefficients between a pair of images, on a per-channel basis. It uses the following equations: w-1 h-1 SUM SUM (d1[x][y][i] * d2[x][y][i]) x=0 y=0 correl[i] = ------------------------------------- s1[i] * s2[i] d1[x][y][i] = img1[x][y][i] - m1[i] d2[x][y][i] = img2[x][y][i] - m2[i] 1 w-1 h-1 m1[i] = ----- * SUM SUM img1[x][y][i] w*h x=0 y=0 1 w-1 h-1 m2[i] = ----- * SUM SUM img2[x][y][i] w*h x=0 y=0 w-1 h-1 s1[i] = sqrt{ SUM SUM (img1[x][y][i] - m1[i])**2 } x=0 y=0 w-1 h-1 s2[i] = sqrt{ SUM SUM (img2[x][y][i] - m2[i])**2 } x=0 y=0 where w and h are the width and height of the images, respectively; m1 and m2 are the mean arrays of the first and second images, respec- tively; s1 and s2 are the un-normalized standard deviation arrays of the first and second images, respectively. In usual cases, the normalized cross-correlation coefficient is in the range of [-1.0, 1.0]. In the case of (s1[i] == 0) or (s2[i] == 0), where a constant image channel is involved, the normalized cross-correlation coefficient is defined as follows: #define signof(x) ((x > 0) ? 1 : ((x < 0) ? -1 : 0)) if ((s1[i] == 0.) || (s2[i] == 0.)) { if ((s1[i] == 0.) && (s2[i] == 0.)) { if (signof(m1[i]) == signof(m2[i]) { correl[i] = 1.0; } else { correl[i] = -1.0; } } else { correl[i] = -1.0; } } The two images must have the same type, the same size, and the same number of channels. They can have 1, 2, 3 or 4 channels. They can be of type MLIB_BYTE, MLIB_SHORT, MLIB_USHORT or MLIB_INT. If (mean2 == NULL) or (sdev2 == NULL), then m2 and s2 are calculated in this function according to the formulas shown above. Otherwise, they are calculated as follows: m2[i] = mean2[i]; s2[i] = sdev2[i] * sqrt(w*h); where mean2 and sdev2 can be the output of mlib_ImageMean() and mlib_ImageStdDev(), respectively. The function takes the following arguments: correl Pointer to normalized cross correlation array on a channel basis. The array must be the size of channels in the images. correl[i] contains the cross-correlation of channel i. img1 Pointer to first image. img2 Pointer to second image. mean2 Pointer to the mean array of the second image. sdev2 Pointer to the standard deviation array of the second image. The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ mlib_ImageAutoCorrel(3MLIB), mlib_ImageAutoCorrel_Fp(3MLIB), mlib_ImageCrossCorrel(3MLIB), mlib_ImageCrossCorrel_Fp(3MLIB), mlib_ImageNorm- CrossCorrel_Fp(3MLIB), attributes(5) 23 May 2005 mlib_ImageNormCrossCorrel(3MLIB)
All times are GMT -4. The time now is 06:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy