Sponsored Content
Full Discussion: awk Script Output Help
Top Forums UNIX for Beginners Questions & Answers awk Script Output Help Post 303031095 by Marquez3105 on Thursday 21st of February 2019 12:46:18 PM
Old 02-21-2019
awk Script Output Help

My code is listed below, I'm trying to figure out what the problem is and what I can do to fix it. The output i'm getting is:



Code:
Name Low High Average
 0 0 0.00



The correct output I want is the name of the Assignment, the lowest score and highest score obtained, and the Average Score under each column. Can Someone help and point me in the right direction



Code:
 awk 'BEGIN{

FS = " "

print "Name Low High Average"

i=0

}

{

if(i==0){

i+=1

}

else{

if(low[$3]<$4)

low[$3] = $4

if(high[$3]>$4 || high[$3]==0)

high[$3] = $4

avg[$3] += $4

cnt[$3] += 1

}

}

END{

for(k in low){

avg[k] = avg[k]/cnt[k]

printf "%s %d %d %.2f ",k, low[k], high[k], avg[k]

}

}' ./Lab03-data.csv


Last edited by RudiC; 02-21-2019 at 06:05 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script the output with awk

Please i need your help. i made this script with awk, this scripts count and list a pattern for each directory in the output as shown. but not as desired. i want the output will be listed in a tabular way, using awk: cuenta_cdrs() { for dir in * do cd $dir for file in * do ... (4 Replies)
Discussion started by: alexcol
4 Replies

2. Shell Programming and Scripting

Format output using awk in script.

Guys, I have a script which hits the database and pulls the information that I need into files. Now I want to format these files to make them easy to read. The sample format of the file will be like.... <Start_of_File> Header1 .....xsdfsfa...adfa...... Header2 ....afefas .aefaefsdf...... (8 Replies)
Discussion started by: bperl
8 Replies

3. Shell Programming and Scripting

Colon in awk script output

I'm using AIX 5.3 and running a awk replace to modify data as follows: echo 1234: 1234 123 123 444 555 666 7777 | awk '/^:/{split($2,N);n=N} {n=$1} {sub(n,n+10000000)}1' 10001234 1234 123 123 444 555 666 7777 dumb question.. how do I get the colon back in, so it outputs 10001234: 1234... (4 Replies)
Discussion started by: say170
4 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

How to get fields and get output with awk or shell script.?

I have a flat file A.txt with field seperate by a pipe 2012/11/13 20:06:11 | 284:hawk pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway 2012/11/14 12:53:51 | ... (6 Replies)
Discussion started by: sabercats
6 Replies

6. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

7. Shell Programming and Scripting

awk Script to format output

Hi all, I'm fairly new to this and learning along the way, so bare with me... I'm trying to format the output from a script to be more read-friendly. The output contains more servers and more processes but for as example it will do: Server: Test1 ... (4 Replies)
Discussion started by: Bobsonm
4 Replies

8. Shell Programming and Scripting

awk script not producing output

Hi, I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt): Blue 6 Red 4 Blue 3 Yellow 4 Red 7 Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies

9. UNIX for Dummies Questions & Answers

Combine Both Output from the awk Script

Hi, Is there anyway to combine output from the awk scripting. file01.txt: AUE_CHMOD AUE_CHOWN AUE_CHROOT AUE_CONNECT AUE_ACCEPT AUE_FCHOWN AUE_FCHMOD AUE_SETREUID AUE_SETREGID AUE_FCHROOT AUE_PFEXEC AUE_SETUID AUE_NICE AUE_SETGID (9 Replies)
Discussion started by: alvinoo
9 Replies

10. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies
mlib_ImageThresh4_Fp(3MLIB)				    mediaLib Library Functions				       mlib_ImageThresh4_Fp(3MLIB)

NAME
mlib_ImageThresh4_Fp - image thresholding SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_ImageThresh4_Fp(mlib_image *dst, const mlib_image *src, const mlib_d64 *thigh, const mlib_d64 *tlow, const mlib_d64 *ghigh, const mlib_d64 *glow); DESCRIPTION
The mlib_ImageThresh4_Fp() function compares each pixel in the source image to two threshold values, tlow and thigh. If the pixel is less than the lower threshold value, tlow, then the destination pixel is set to the lower output level, glow. If the pixel is greater than the higher threshold value, thigh, then the destination pixel is set to the higher output level, ghigh. Otherwise, the destination pixel is set to the value of the source pixel. It uses the following equation: dst[x][y][i] = glow[i] if src[x][y][i] < tlow[i] dst[x][y][i] = src[x][y][i] if tlow[i] <= src[x][y][i] <= thigh[i] dst[x][y][i] = ghigh[i] if src[x][y][i] > thigh[i] PARAMETERS
The function takes the following arguments: dst Pointer to destination image. src Pointer to source image. thigh High threshold value. thigh[i] holds the high threshold for channel i. tlow Low threshold value. tlow[i] holds the low threshold for channel i. ghigh High output grayscale level. ghigh[i] holds the high output grayscale level for channel i. glow Low output grayscale level. glow[i] holds the low output grayscale level for channel i. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_ImageThresh1(3MLIB), mlib_ImageThresh1_Fp(3MLIB), mlib_ImageThresh1_Fp_Inp(3MLIB), mlib_ImageThresh1_Inp(3MLIB), mlib_ImageTh- resh2(3MLIB), mlib_ImageThresh2_Fp(3MLIB), mlib_ImageThresh2_Fp_Inp(3MLIB), mlib_ImageThresh2_Inp(3MLIB), mlib_ImageThresh3(3MLIB), mlib_ImageThresh3_Fp(3MLIB), mlib_ImageThresh3_Fp_Inp(3MLIB), mlib_ImageThresh3_Inp(3MLIB), mlib_ImageThresh4(3MLIB), mlib_ImageTh- resh4_Fp_Inp(3MLIB), mlib_ImageThresh4_Inp(3MLIB), mlib_ImageThresh5(3MLIB), mlib_ImageThresh5_Fp(3MLIB), mlib_ImageThresh5_Fp_Inp(3MLIB), mlib_ImageThresh5_Inp(3MLIB), attributes(5) SunOS 5.11 2 Mar 2007 mlib_ImageThresh4_Fp(3MLIB)
All times are GMT -4. The time now is 06:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy