Sponsored Content
Operating Systems HP-UX Shell /awk script for Percentage Post 303019136 by Don Cragun on Saturday 23rd of June 2018 11:20:50 PM
Old 06-24-2018
Maybe something like:
Code:
awk '
BEGIN {	FS = OFS = "|"
}
NR == 1 {
	print $0, "C"
	next
}
{	gsub(/ /, "")
	if($1 $2 ~ /[^0-9]/)
		$3 = "NA"
	else	$3 = $2 / $1 * 100 "%"
}
1' file

will give you what you want? (Note that this assumes that all <space>s in fields 1 and 2 should be deleted, while the code Ravinder suggested only deletes trailing <space>s in those two fields.)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk percentage

how would you calculate percentage by per line? Given a column of 16 lines, grab each line and divide it by the sum of the entire column and multiply by 100? thanks ... (8 Replies)
Discussion started by: rockiefx
8 Replies

2. Shell Programming and Scripting

Need an AWK script to calculate the percentage

Hi I need a awk script to calculate percentage. I have to pass the pararmeters in to the awk script and calculate the percentage. Sum = 50 passed = 43 failed = 7 I need to pass these value in to the awk script and calculate the percentage. Please advice me. (8 Replies)
Discussion started by: bobprabhu
8 Replies

3. Shell Programming and Scripting

awk script to count percentage from log file

Hi, I have a log like this : actually i want to get the log like this : where % can get from : 100 * pmTotNoRrcConnectReqSucc / pmTotNoRrcConnectReq Thanks in advance.. :) (8 Replies)
Discussion started by: justbow
8 Replies

4. Shell Programming and Scripting

Script shell, how to calculate percentage?

hello, please can you help me. jj and kk are two numbers which are the result of an sql program. I would like to calculate the ratio jj/kk*100. I have done this: ratio=$((jj/kk * 100)) or ratio=`expr $jj \/ expr $kk) but the result is 0 What can i do? Thanks for help. (3 Replies)
Discussion started by: likeaix
3 Replies

5. Programming

Shell script to find Percentage?

Hi all, I havea log of data.log bear,10000,white bear,5000,black chicken,2000,white chicken,4000,yellow chicken,3000,black lion,6000,yellow lion,1000,white How can we have shell script to get the percentage of each animals? Thanks. (8 Replies)
Discussion started by: sabercats
8 Replies

6. Shell Programming and Scripting

Need an awk script to calculate the percentage of value field and replace

Need an awk script to calculate the percentage of value field and replace I have a input file called file.txt with the following content: john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2 andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1 in fourth filed of input file, calulate percentage of each... (1 Reply)
Discussion started by: veeruasu
1 Replies

7. UNIX for Dummies Questions & Answers

Need an awk script to calculate the percentage of value field and replace

I have a input file called file.txt with the following content: john|622.5674603562933|8|br:1;cn:3;fr:1;jp:1;us:2 andy|0.0|12|**:3;br:1;ca:2;de:2;dz:1;fr:2;nl:1 in fourth filed of input file, calulate percentage of each sub filed seperated by ; semicolon and replace value with percentage . i... (11 Replies)
Discussion started by: veeruasu
11 Replies

8. Shell Programming and Scripting

find percentage - awk

Please help me with this ... Input file /vol/test1 10G /vol/test2 1G /vol/test3 200G /vol/test4 3G Output File /vol/test1 10G - - 9G - /vol/test2 1024M - - 921M - /vol/test3 200G - - 180G - /vol/test4 3072M - - 2764M - Basically if Column 2 ( which is... (6 Replies)
Discussion started by: greycells
6 Replies

9. UNIX for Dummies Questions & Answers

Percentage / Multiplication in Shell Script

Hello, I am trying to compute the percentage in a script as shown below: PerCover=`echo "scale=2 ; 100 \* ($InputCover/$Total)" | bc` However the PerCover value is blank/null. What do I need to do differently? Thanks for your input! ~Guss (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

10. UNIX for Beginners Questions & Answers

Working out percentage in shell script

Hi All, I currently have a shell script which is pulling multiple counters from various sources. Due to the counters being cumulative counters I've got some code to work out the delta from the last reading and current which is working fine. The problem i have now is being able to work out the... (8 Replies)
Discussion started by: mutley2202
8 Replies
Prima::DetailedList(3)					User Contributed Perl Documentation				    Prima::DetailedList(3)

NAME
Prima::DetailedList - a multi-column list viewer with controlling header widget. SYNOPSIS
use Prima::DetailedList; my $l = $w-> insert( 'Prima::DetailedList', columns => 2, headers => [ 'Column 1', 'Column 2' ], items => [ ['Row 1, Col 1', 'Row 1, Col 2'], ['Row 2, Col 1', 'Row 2, Col 2'] ], ); $l-> sort(1); DESCRIPTION
Prima::DetailedList is a descendant of Prima::ListViewer, and as such provides a certain level of abstraction. It overloads format of items in order to support multi-column ( 2D ) cell span. It also inserts Prima::Header widget on top of the list, so the user can interactively move, resize and sort the content of the list. The sorting mechanism is realized inside the package; it is activated by the mouse click on a header tab. Since the class inherits Prima::ListViewer, some functionality, like 'item search by key', or "get_item_text" method can not operate on 2D lists. Therefore, mainColumn property is introduced, that selects the column representing all the data. API
Events Sort COLUMN, DIRECTION Called inside sort method, to facilitate custom algorithms of sorting. If the callback procedure is willing to sort by COLUMN index, then it must call "clear_event", to signal the event flow stop. The DIRECTION is a boolean flag, specifying whether the sorting must be performed is ascending ( 1 ) or descending ( 0 ) order. The callback procedure must operate on the internal storage of "{items}", which is an array of arrays of scalars. The default action is the literal sorting algorithm, where precedence is arbitrated by "cmp" operator ( see "Equality Operators" in perlop ) . Properties columns INTEGER Governs the number of columns in items. If set-called, and the new number is different from the old number, both items and headers are restructured. Default value: 0 headerClass Assigns a header class. Create-only property. Default value: "Prima::Header" headerProfile HASH Assigns hash of properties, passed to the header widget during the creation. Create-only property. headerDelegations ARRAY Assigns a header widget list of delegated notifications. Create-only property. headers ARRAY Array of strings, passed to the header widget as column titles. items ARRAY Array of arrays of scalars, of arbitrary kind. The default behavior, however, assumes that the scalars are strings. The data direction is from left to right and from top to bottom. mainColumn INTEGER Selects the column, responsible for representation of all the data. As the user clicks the header tab, "mainColumn" is automatically changed to the corresponding column. Default value: 0 Methods sort [ COLUMN ] Sorts items by the COLUMN index in ascending order. If COLUMN is not specified, sorts by the last specified column, or by #0 if it is the first "sort" invocation. If COLUMN was specified, and the last specified column equals to COLUMN, the sort direction is reversed. The method does not perform sorting itself, but invokes Sort notification, so the sorting algorithms can be overloaded, or be applied differently to the columns. AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>. SEE ALSO
Prima, Prima::Lists, Prima::Header, examples/sheet.pl perl v5.14.2 2009-02-24 Prima::DetailedList(3)
All times are GMT -4. The time now is 07:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy