Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Problem with getting awk to multiply a field by a value set based on condition of another field Post 303043634 by cotilloe on Sunday 2nd of February 2020 03:20:47 PM
Old 02-02-2020
That actually helps alot, as I had tried something like that. What I tried to do was:

Code:
SUM[$1] += $4*0.1

That did not work, but by storing the weights in in an array, I see how it could be workable. My only question is how to store/use multiple values.
If $2 = Homework then $4 needs to be multiplied by 0.1
if $2 = Quiz then $4 needs to be multiplied by 0.4
if $2 = Lab then $4 needs to be multiplied by 0.3
if $2 = Final then $4 needs to be multiplied by 0.15
if $2 = Survey then $4 needs to be multiplied by 0.05

Then, all I would need to do is some $4 with the new values and have the overall percent for each student.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field. For example if N=3, we want the 3 best values for each entry: Entry1 ||| 100 Entry1 ||| 95 Entry1 ||| 30 Entry1 ||| 80 Entry1 ||| 50 Entry2 ||| 40 Entry2 ||| 20 Entry2 ||| 10 Entry2 ||| 50... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

2. UNIX for Dummies Questions & Answers

awk - Summing a field based on another field

So, I need to do some summing. I have an Apache log file with the following as a typical line: 127.0.0.1 - frank "GET /apache_pb.gif HTTP/1.0" 200 2326 Now, what I'd like to do is a per-minute sum. So, I can have awk tell me the individual minutes, preserving the dates(since this is a... (7 Replies)
Discussion started by: treesloth
7 Replies

3. Shell Programming and Scripting

Update a field in a file based on condition

Hi i am new to scripting. i have a file file.dat with content as : CONTENT_STORAGE PERCENTAGE FLAG: /storage_01 64% 0 /storage_02 17% 1 I need to update the value of FLAG for a particular CONTENT_STORAGE value I have written the following code #!/bin/sh threshold=20... (1 Reply)
Discussion started by: kichu
1 Replies

4. Shell Programming and Scripting

Help with Awk finding and replacing a field based on a condition

Hi everybody, I'm trying to replace the $98 field with "T" if the last field (108th) is T I've tried awk 'BEGIN{OFS=FS="|"} {if ($108=="T")sub($98,"T"); print}' test.txt but that doesn't do anything also tried awk 'BEGIN{OFS=FS="|"}{ /*T.$/ sub($98,"T")} { print}' test.txt but... (2 Replies)
Discussion started by: jghi123
2 Replies

5. Shell Programming and Scripting

awk to count condition in field

I am trying to confirm the counts from another code and tried the below awk, but the syntax is incorrect. Basically, outputting the counts of each condition in $8. Thank you :) awk '$8==/TYPE=snp/ /TYPE=ins/ /TYPE=del/ {count++} END{print count}'... (6 Replies)
Discussion started by: cmccabe
6 Replies

6. Shell Programming and Scripting

awk to update value in field based on another field

In the tab-delimeted input file below I am trying to use awk to update the value in $2 if TYPE=ins in bold, by adding the value of HRUN= in italics. In the below since in line 1 TYPE=ins the 117282541 value in $2 has 6 added because that is the value of HRUN=. Hopefully the awk is a start but I... (2 Replies)
Discussion started by: cmccabe
2 Replies

7. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

8. Shell Programming and Scripting

Perl to update field based on a specific set of rules

In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f. There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Discussion started by: cmccabe
5 Replies

9. Shell Programming and Scripting

awk to change contents of field based on condition in same file

In the awk below I am trying to copy the entire contents of $6 there may be multiple values seperated by a ;, to $8, if $8 is . (lines 1 and 3 are examples). If that condition $8 is not . (line2 is an example) then that line is skipped and printed as is. The awk does execute but prints the output... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. UNIX for Beginners Questions & Answers

Change the field color based on condition in email

Request your help to change the field color based on condition , if it is otherthan 0. using html in unix. Here is my condition for(i=1;i<=NF;i++) { print "<td> "$i"</td> } Please use CODE tags when displaying sample input, output, and code segments. (17 Replies)
Discussion started by: CatchMe
17 Replies
GLACCUM(3G)							   OpenGL Manual						       GLACCUM(3G)

NAME
glAccum - operate on the accumulation buffer C SPECIFICATION
void glAccum(GLenum op, GLfloat value); PARAMETERS
op Specifies the accumulation buffer operation. Symbolic constants GL_ACCUM, GL_LOAD, GL_ADD, GL_MULT, and GL_RETURN are accepted. value Specifies a floating-point value used in the accumulation buffer operation. op determines how value is used. DESCRIPTION
The accumulation buffer is an extended-range color buffer. Images are not rendered into it. Rather, images rendered into one of the color buffers are added to the contents of the accumulation buffer after rendering. Effects such as antialiasing (of points, lines, and polygons), motion blur, and depth of field can be created by accumulating images generated with different transformation matrices. Each pixel in the accumulation buffer consists of red, green, blue, and alpha values. The number of bits per component in the accumulation buffer depends on the implementation. You can examine this number by calling glGetIntegerv() four times, with arguments GL_ACCUM_RED_BITS, GL_ACCUM_GREEN_BITS, GL_ACCUM_BLUE_BITS, and GL_ACCUM_ALPHA_BITS. Regardless of the number of bits per component, the range of values stored by each component is -1 1. The accumulation buffer pixels are mapped one-to-one with frame buffer pixels. glAccum operates on the accumulation buffer. The first argument, op, is a symbolic constant that selects an accumulation buffer operation. The second argument, value, is a floating-point value to be used in that operation. Five operations are specified: GL_ACCUM, GL_LOAD, GL_ADD, GL_MULT, and GL_RETURN. All accumulation buffer operations are limited to the area of the current scissor box and applied identically to the red, green, blue, and alpha components of each pixel. If a glAccum operation results in a value outside the range -1 1, the contents of an accumulation buffer pixel component are undefined. The operations are as follows: GL_ACCUM Obtains R, G, B, and A values from the buffer currently selected for reading (see glReadBuffer()). Each component value is divided by 2 n - 1, where n is the number of bits allocated to each color component in the currently selected buffer. The result is a floating-point value in the range 0 1, which is multiplied by value and added to the corresponding pixel component in the accumulation buffer, thereby updating the accumulation buffer. GL_LOAD Similar to GL_ACCUM, except that the current value in the accumulation buffer is not used in the calculation of the new value. That is, the R, G, B, and A values from the currently selected buffer are divided by 2 n - 1, multiplied by value, and then stored in the corresponding accumulation buffer cell, overwriting the current value. GL_ADD Adds value to each R, G, B, and A in the accumulation buffer. GL_MULT Multiplies each R, G, B, and A in the accumulation buffer by value and returns the scaled component to its corresponding accumulation buffer location. GL_RETURN Transfers accumulation buffer values to the color buffer or buffers currently selected for writing. Each R, G, B, and A component is multiplied by value, then multiplied by 2 n - 1, clamped to the range 0 2 n - 1, and stored in the corresponding display buffer cell. The only fragment operations that are applied to this transfer are pixel ownership, scissor, dithering, and color writemasks. To clear the accumulation buffer, call glClearAccum() with R, G, B, and A values to set it to, then call glClear() with the accumulation buffer enabled. NOTES
Only pixels within the current scissor box are updated by a glAccum operation. ERRORS
GL_INVALID_ENUM is generated if op is not an accepted value. GL_INVALID_OPERATION is generated if there is no accumulation buffer. GL_INVALID_OPERATION is generated if glAccum is executed between the execution of glBegin() and the corresponding execution of glEnd(). ASSOCIATED GETS
glGet() with argument GL_ACCUM_RED_BITS glGet() with argument GL_ACCUM_GREEN_BITS glGet() with argument GL_ACCUM_BLUE_BITS glGet() with argument GL_ACCUM_ALPHA_BITS SEE ALSO
glClear(), glClearAccum(), glCopyPixels(), glDrawBuffer(), glGet(), glReadBuffer(), glReadPixels(), glScissor(), glStencilOp() COPYRIGHT
Copyright (C) 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/. AUTHORS
opengl.org opengl.org 06/10/2014 GLACCUM(3G)
All times are GMT -4. The time now is 12:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy