[awk] Math & Bold-Font?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [awk] Math & Bold-Font?
# 15  
Old 02-17-2015
Thank you RudiC for the updated code, sadly, one cant double thank in such situations.

So what i have now is this, with these questions:
Code:
	ln10=log(10)	# What is this for?
	#print ln10	## 2.30259

Really, i can make no sense of it, maybe i'm too focused on the number?

Code:
	# Again what for is ln10 used here and XP prepared for? And what is done anwyay?
	XP=int(log(NBR)/ln10/3)
	# print XP # = 1 or 0

Well i understand the 'order' of the math i guess, make a LOG-number from the passed NBR, and then do-something with 2.30259/3 and finaly make that an int-number.
Is that about right?
Guess the best to describe my question: i cant figure out the formula beeing used (actualy its naturaly spoken 'syntax').

Code:
	# sprintf is one topic, but what is why done with XP (1 or 0)?
	return sprintf ("%.2f%s", NBR / 10^(3*XP), U[1+XP])

Its passed NBR divided by 10 square 3 times either 0 or 1, and selecting its output string according to passed array U. (? 1+XP == XP+1 ?)
Is XP here used like 'shift' with 'getopts' (or just similar tasks)?

Code:
	# How can i check for the current line its [BP]UNT value?
	if("B" == U) { 		# This still prints output, but doesnt do the changes wanted
	## if("B" == BUNT) {	# This way it prints absolute nothing ??
		split(bitrate,B,".")
		bitrate=B[1]
	}

I've also tried if("B" in BUNT) without luck either Smilie
This last one is an attempt to remove the .00 of the bitrate colum for the values not exceeding the Byte range.

Thank you in advance for clearing up.
Have a good day!
# 16  
Old 02-17-2015
Quote:
Originally Posted by sea
Code:
    ln10=log(10)    # What is this for?
    #print ln10    ## 2.30259

Really, i can make no sense of it, maybe i'm too focused on the number?
awk only offers log which really and correctly is ln, the "logarithmus naturalis", based on the number "e".

ln (1000) = 6,9077... . Divide this by ln (10) = 2.30259... and - voila - you'll get exactly 3, the count of zeroes in 1000 (actually the logarithm to the base 10, log10). Same holds true for e.g. 100000 or any real number.
log10 (50 ) = 1,69897
log10 (500 ) = 2,69897
log10 (5000 ) = 3,69897
log10 (50000) = 4,69897 ... see the pattern?
I use this to get the count of digits in a number.

But - we're intereseted in digit count in steps of three 1 - 1000 - 1000000 - etc., so read on

Quote:
Code:
    # Again what for is ln10 used here and XP prepared for? And what is done anwyay?
    XP=int(log(NBR)/ln10/3)
    # print XP # = 1 or 0

In this function the exponent to base 10 of the parameter NBR is calculated, and, as we're interested in steps of three only, divided by three, and int'ed (chopping off the .69897 or so). XP's value will be 0 for NBR up to 1000, 1 up to 1000000, 2 up to 1E9, etc. (Here lies a little problem, as for exactly 1000 etc., XP will be one too small). I admit, the name XP may be a bit misleading, as it is "exponent / 3"

Quote:
Code:
    # sprintf is one topic, but what is why done with XP (1 or 0)?
    return sprintf ("%.2f%s", NBR / 10^(3*XP), U[1+XP])

Its passed NBR divided by 10 square 3 times either 0 or 1, and selecting its output string according to passed array U. (? 1+XP == XP+1 ?)
^ does not mean "square", but "exponentiation". So we divide NBR by 1 if XP==0, 1000 if XP==1, 1E6 if XP==2. The 3* is to compensate for the /3 BEFORE int'ing. 5120 becomes 5.12 etc.
XP also is used as the index into the unit fields BUNT and PUNT, which, alas, start from 1 and not from 0.

Quote:
Is XP here used like 'shift' with 'getopts' (or just similar tasks)?
No.

Quote:
Code:
    # How can i check for the current line its [BP]UNT value?
    if("B" == U) {         # This still prints output, but doesnt do the changes wanted
    ## if("B" == BUNT) {    # This way it prints absolute nothing ??
        split(bitrate,B,".")
        bitrate=B[1]
    }

Both arrays are assigned in the BEGIN section from strings containing unit abbreviations. Read them "ByteUnits" and "PixelUnits". Indices are 1 .. 4. Use them like BUNT[2]. Or {for (b in BUNT) print b, BUNT[b]}

Quote:
I've also tried if("B" in BUNT) without luck either
Can be 1 (or 2..4) in BUNT only.


I have to apologize for the misleading variable nomenclature. An idiosyncrasy (from old FORTRAN days?) that I should have overcome looong ago, nowadays that spending some more chars on names will help people incl. myself understand programs.
This User Gave Thanks to RudiC For This Post:
# 17  
Old 02-17-2015
Bold is pretty terminal specific, and done in the presentation layer. Always design presentation on the end, after the data is parsed. Do you really want the shell to be the presentation tool? HTML is much more portable as a text formatting output, using <B>for BOLD</B> and <table>'s, <td> options for alignment.
This User Gave Thanks to DGPickett For This Post:
# 18  
Old 02-17-2015
Valid argument, but its for a help text printed in the shell.
As in: script.sh -h
The bold text indicates (one kind of) the arguments to pass to the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Slowly Removing Bold Font Style - Step-by-Step

FYI, I'm slowly removing a lot of the bold font-styles from titles of discussions, forum titles, etc I'm not removing bold for the entire site because we do need bold from time to time, especially in posts and sometimes in other places. However, the original forum style had way too much... (3 Replies)
Discussion started by: Neo
3 Replies

2. Shell Programming and Scripting

Math count %memory using awk

Hi expert, i have log this: Memory: 74410384 Memory: 75831176 Memory: 77961232 Memory: 77074656 Memory: 76086160 Memory: 77128592 Memory: 78045384 Memory: 76696040 Memory: 72401176 Memory: 72520016 Memory: 72137016 Memory: 73175832 Memory: 73034528 Memory: 71770736 Memory:... (4 Replies)
Discussion started by: justbow
4 Replies

3. Shell Programming and Scripting

Count math using awk

Hi expert, I have log : TOTAL-TIME : 2125264636 DATA-BYTES-DOWN : 3766111307032 DATA-BYTES-UP : 455032157567 DL = (3766111307032/2125264636)/1024 = 1.73 UL = (455032157567/2125264636)/1024 = 0.21 I want the result : TOTAL = 1.94 ... (4 Replies)
Discussion started by: justbow
4 Replies

4. Shell Programming and Scripting

awk --> math-operation in a array

Hi main object is categorize the difference of data-values (TLUFT02B - TLUFT12B). herefor i read out data-files which are named acording to the timeformat yyyymmddhhmm. WR030B 266.48 Grad 0 WR050B 271.46 Grad 0 WR120B 268.11 Grad 0 WV030B 2.51 m/s ... (6 Replies)
Discussion started by: IMPe
6 Replies

5. Shell Programming and Scripting

awk in horizontal and vertical math

Based on input ail,UTT,id1_0,COMBO,21,24,21,19,85 al,UTHAST,id1_0,COMBO,342,390,361,361,1454 and awk code as awk -F, '{ K=0; for(i=NF; i>=(NF-4); i--) { K=K+$i; J=J+$i;} { print K } } END { for ( l in J ) printf("%s ",J); }' I'm trying to add columns and lines in single line. line... (6 Replies)
Discussion started by: busyboy
6 Replies

6. Shell Programming and Scripting

awk math and csv output

Hi I have this list 592;1;Z:\WB\DOCS;/FS3_100G/FILER112/BU/MPS/DOCS;;;;\\FILER112\BUMPS-DOCS\;580,116,544,878 Bytes;656,561 ;77,560 592;2;Z:\WB\FOCUS;/FS3_100G/FILER112/BU/MPS/FOCUS;;;;\\FILER112\BUMPS-FOCUS\;172,430 Bytes;6 ;0 ... (12 Replies)
Discussion started by: nakaedu
12 Replies

7. Shell Programming and Scripting

output text in bold font using SED

hi I want to write a script, while using the SED editor, to output the text, in this case a variable, to the result file but highlighted it in bold, is it possible to do that? can you tell me how? eg. in text.txt sed '$ a\ '$variable' ' <text.txt >text2.txt so it will add the... (2 Replies)
Discussion started by: piynik
2 Replies

8. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

9. UNIX for Dummies Questions & Answers

colored/highlighted/bold matching pattern with awk ???

Hi ! Just wondering, is it possible to color or highlight or underline a matching pattern with awk ? Or write it in bold, italic.....? (3 Replies)
Discussion started by: lucasvs
3 Replies

10. UNIX for Dummies Questions & Answers

awk logic and math help

Hi, My file has 2 fields and millions of lines. variableStep chrom=Uextra span=25 201 0.5952 226 0.330693 251 0.121004 276 0.0736858 301 0.0646982 326 0.0736858 401 0.2952 426 0.230693 451 0.221004 476 0.2736858 Each field either has a... (6 Replies)
Discussion started by: wyarosh
6 Replies
Login or Register to Ask a Question