Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Add column and multiply its result to all elements of another column Post 303032062 by Sagar Singh on Sunday 10th of March 2019 03:28:12 PM
Old 03-10-2019
sir, I am a trainee in a telecom company and this is the daily routine work I have to do this daily, that's why I am trying to automate it using Linux scripting

Actual question is
Code:
mss1:BSCNND2  12367     6.3  
mss2:BSCNND2  11418     6.3  
mss3:BSCNND2  10945     6.3 
mss4:BSCNND2  10898     6.3 
mss6:BSCNND2  13298     7.4  
bc01:BSCNAN2  66546     34.5
bc02:BSCNND2  58478     32.9

Required output is :

Code:
BSCNND2    12367    6.3      Sum of $2*6.3/100
BSCNND2    11418    6.3      Sum of $2*6.3/100
BSCNND2    10945    6.3      Sum of $2*6.3/100
BSCNND2    10898    6.3      Sum of $2*6.3/100
BSCNND2    13298    7.4      Sum of $2*7.4/100
BSCNAN2    66546    34.5     Sum of $2*34.5/100
BSCNND2    58478    32.9     Sum of $2*32.9/100

These values are changing on the basis of daily logs generated (earlier post was just an example)

--- Post updated at 07:28 PM ---

Code:
egrep "BSCNND2|BSCNAN2" mss? bc0? > bscnnd2 && paste bscnnd2 RLCAP.txt | awk '{sum+=$2} {print $0," "sum*$3}'

Geting this output

Code:
mss1:BSCNND2  12367     6.3  77912.1
mss2:BSCNND2  11418     6.3  149846
mss3:BSCNND2  10945     6.3  218799
mss4:BSCNND2  10898     6.3  287456
mss6:BSCNND2  13298     7.4  436052
bc01:BSCNAN2  66546     34.5 4328784
bc02:BSCNND2  58478     32.9 6051955

but required output is
Code:
BSCNND2    12367    6.3    1158885
BSCNND2    11418    6.3    1158885
BSCNND2    10945    6.3    1158885
BSCNND2    10898    6.3    1158885
BSCNND2    13298    7.4    1361230
BSCNAN2    66546    34.5   6346275
BSCNND2    58478    32.9   6051955

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-10-2019 at 04:51 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiply whole column with a value

Hi, I need to multiply 3rd column (comma seperated) of entire file by a value say 2.2. Suppose the file is: C,Gas $ YTD(TRI),15512.36,01/01/2010 New file should be (3rd column value multiplied by 2.2): C,Gas $ YTD(TRI),34127.192,01/01/2010 (5 Replies)
Discussion started by: yale_work
5 Replies

2. Shell Programming and Scripting

Need to add letters to a column and add in a new column subtracting from another column

So I have this input 1 10327 rs112750067 T C . PASS DP=65;AF=0.208;CB=BC,NCBI 1 10469 rs117577454 C G . PASS DP=2055;AF=0.020;CB=UM,BC,NCBI 1 10492 rs55998931 C T . PASS DP=231;AF=0.167;CB=BC,NCBI 1 10583 rs58108140 G A ... (3 Replies)
Discussion started by: kellywilliams
3 Replies

3. UNIX for Dummies Questions & Answers

Average for repeated elements in a column

I have a file that looks like this 452 025_E3 8 025_E3 82 025_F5 135 025_F5 5 025_F5 23 025_G2 38 025_G2 71 025_G2 9 026_A12 81 026_A12 10 026_A12 some of the elements in column2 are repeated. I want an output file that will extract the... (1 Reply)
Discussion started by: FelipeAd
1 Replies

4. Shell Programming and Scripting

to add special tag to a column based on column condition

Hi All, I have following html code <TR><TD>9</TD><TD>AR_TVR_TBS </TD><TD>85000</TD><TD>39938</TD><TD>54212</TD><TD>46</TD></TR> <TR><TD>10</TD><TD>ASCV_SMY_TBS </TD><TD>69880</TD><TD>33316</TD><TD>45698</TD><TD>47</TD></TR> <TR><TD>11</TD><TD>ARC_TBS ... (9 Replies)
Discussion started by: ckwan
9 Replies

5. Shell Programming and Scripting

Filtering lines for column elements based on corresponding counts in another column

Hi, I have a file like this ACC 2 2 21 aaa AC 443 3 22 aaa GCT 76 1 33 xxx TCG 34 2 33 aaa ACGT 33 1 22 ggg TTC 99 3 44 wee CCA 33 2 33 ggg AAC 1 3 55 ddd TTG 10 1 22 ddd TTGC 98 3 22 ddd GCT 23 1 21 sds GTC 23 4 32 sds ACGT 32 2 33 vvv CGT 11 2 33 eee CCC 87 2 44... (1 Reply)
Discussion started by: polsum
1 Replies

6. Shell Programming and Scripting

Multiply certain column to variable

Hi experts, I want to multiply certain columns to variable, data : 1 2 3 4 5 6 7 8 9 result with var = 2 for column 3,6,9 ... (every columns which can be divided to 3): 1 2 6 4 5 12 7 8 18 I have tried : awk 'BEGIN{FS=OFS=" "}{print $1,$2,$3*a,$4,$5,$6*a,$7,$8,$9*2 }' a=2 file.txt but how... (6 Replies)
Discussion started by: guns
6 Replies

7. Shell Programming and Scripting

Counting specific column and add result in output

Hi all, I have a quick question: I have a 4 column tab-separated file. I want to count the number of times each unique value in column 2 appears and add that number in a 5th column. I have the following input file: waterline-n below-sheath-v 14.8097 A dock-n below-sheath-v ... (4 Replies)
Discussion started by: owwow14
4 Replies

8. Shell Programming and Scripting

Count common elements in a column

HI, I have a 3-column tab separated column (approx 1GB) in which I would like to count and output the frequency of all of the common elements in the 1st column. For instance: If my input was the following: dot is-big 2 dot is-round 3 dot is-gray 4 cat is-big 3 hot in-summer 5 My... (4 Replies)
Discussion started by: owwow14
4 Replies

9. Shell Programming and Scripting

Matching column and search closest elements

Hi all I have a great challenge that I am not able to resolve. Briefly, I have a file like this: ID_1 chr1 100 - ID_2 chr2 300 + and another file like this: name_1 chr1 150 no - name_2 chr1 250 yes - name_3 chr2 350 yes + name_4 chr2 280 yes + Well, for each entry in file1 I would... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

10. UNIX for Beginners Questions & Answers

Multiply elements of 2 arrays together into another array

So I need to Write an array processing program using a Linux shell programming language to perform the following. Load array X of 20 numbers from an input file X. Load array Y of 20 numbers from an input file Y. Compute array Z by multiply Xi * Yi then compute the square-root of this... (2 Replies)
Discussion started by: sarapham409
2 Replies
All times are GMT -4. The time now is 10:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy