[Solved] awk Errors on notation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] awk Errors on notation
# 1  
Old 02-25-2014
[Solved] awk Errors on notation

can someone spot what i'm doing wrong here:

Code:
awk 'BEGIN{printf("%0.2f", 1 / 2649320) * 100}'

i get this error:

Code:
awk: line 1: syntax error at or near *

then i do this and get the answer i'm trying to avoid:

Code:
awk 'BEGIN{print(1 / 2649320) * 100}'

Code:
3.77455e-05

# 2  
Old 02-25-2014
The awk utility is interpreting:
Code:
awk 'printf("%0.2f", 1 / 2649320) * 100'

as:
Code:
(printf("%0.2f", 1 / 2649320)) * 100

and you are getting an error because the awk printf() function does not return a numeric value. If I understand what you're trying to do, try:
Code:
awk 'BEGIN{printf("%0.2f", (1 / 2649320) * 100)}'

or:
Code:
awk 'BEGIN{printf("%0.2f", 100 / 2649320)}'

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-25-2014
Well, I am not sure why printf behaves that way, may it is not programmed to return the value but just print it out? May be it is not a function?

However, I think may be you want this?
Code:
awk 'BEGIN{print sprintf("%0.2f", 1 / 2649320) * 100}'

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 4  
Old 02-25-2014
sorry guys. i should have gave more explanation. the answer:

Code:
3.77455e-05

is correct.

i just want to get rid of the notation. and i was hoping the 0.2f would deal with that but evidently, it's not. Smilie
# 5  
Old 02-25-2014
You need to increase the decimal range

Code:
# awk 'BEGIN{printf("%0.10f", 100 / 2649320)}'
0.0000377455

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 6  
Old 02-25-2014
Quote:
Originally Posted by SkySmart
sorry guys. i should have gave more explanation. the answer:

Code:
3.77455e-05

is correct.

i just want to get rid of the notation. and i was hoping the 0.2f would deal with that but evidently, it's not. Smilie
I hope that ahamed101 has already suggested the solution you're looking for, but I'm not sure we understand what you mean by "i (sic) just want to get rid of the notation".

If you aren't looking for fixed decimal notation with 10 digits after the radix character, what notation do you want? You might also want to look at the awk man page's description of the OFMT variable (which has a default value of %.6g).
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 02-26-2014
Hi.

I'm guessing that he means the common phrase scientiic notation with e, as in e-05 ... cheers, drl

... usually referred to as (scientific) E notation or (scientific) e notation, rather than (scientific) exponential notation (though the latter also occurs). The use of this notation is not encouraged in publications ... from Scientific notation - Wikipedia, the free encyclopedia

Last edited by drl; 02-26-2014 at 09:07 AM.. Reason: Add citation.
This User Gave Thanks to drl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Context for use of [.symbol.] awk notation

Hi Just wondering ... do you have an example of context that would demonstrates how usefull the awk notation can efficiently be used ? Thx :rolleyes: (6 Replies)
Discussion started by: ctsgnb
6 Replies

2. Shell Programming and Scripting

Help with filter result (scientific notation) by using awk

Input file: data1 0.05 data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 data1 4e-9 Desired output: data2 1e-14 data1 1e-330 data2 1e-14 data5 2e-60 data5 2e-150 I would like to filter out those result that column 2 is less than 1e-10. Command try: (1 Reply)
Discussion started by: cpp_beginner
1 Replies

3. Shell Programming and Scripting

Perl: scientific notation to decimal notation

hello folks, I have few values in a log which are in scientific notation. I am trying to convert into actual decimal format or integer but couldn't able to convert. Values in scientific notation: 1.1662986666666665E-4 2.0946799999999998E-4 3.0741333333333333E-6 5.599999999999999E-7... (2 Replies)
Discussion started by: scriptscript
2 Replies

4. Shell Programming and Scripting

Get rid of awk notation

echo 0.633588 1875 | awk '{print $1 * $2 * 1024}' is there a better way to run the above command? it keeps printing out in notation and i do not want that at all. when i run the above, i get: 1.21649e+06 OS: linux language:bash (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Programming

Errors in Perl when using awk command

Hi Guys, Hope everyone is fine :) I have this code below: #!/usr/bin/perl $num_of_files=`ls | grep -v remover | wc -l`; $remover=`ls -lrt | grep -v total | grep -v remover | head -1 | awk '{print $8}' | rm \`xargs\``; if ($num_of_files>3) { system ($remover); } When I... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

6. HP-UX

[Solved] Startup script errors?

The below text is displayed on the console -> sbin/rc2.d/S130pfilboot: -l: not found. /sbin/rc2.d/S131ipfboot: -l: not found. /sbin/rc2.d/S590Rpcd: -l: not found. /sbin/rc2.d/S700acct: -l: not found. /sbin/rc2.d/S900drd: -l: not found. /sbin/rc3.d/S823hpws22_apache: -l: not found.... (4 Replies)
Discussion started by: pplayford
4 Replies

7. Shell Programming and Scripting

Convert decimal notation to ANSI point code notation

wondering if anyone has any thoughts to convert the below thru a shell script Convert decimal signalling point notation to ANSI point code notation There is a site that does that conversion but i need to implement the solution in a shell script.....Thoughts.... OS: Solaris 9 ... (4 Replies)
Discussion started by: aavam
4 Replies

8. Shell Programming and Scripting

Turning off exponential notation in awk

I have various numbers that I'm printing out from a statistical summary script. I'd like it to stop using exponential format. Of course, I can use printf with 'd' and 'f' and various parameters to specify a format, but then it has other undesirable effects, like tacking on extra 0's or truncating... (0 Replies)
Discussion started by: treesloth
0 Replies

9. Shell Programming and Scripting

awk errors

Hello, Can you please let me know how to find all lines that don't begin with pattern1, pattern2, pattern3 and pattern4? Here is my awk script that gives an error. awk 'BEGIN { NAME="$FILE" GSNO=0 } /^ISA/ { FIRST=$0; LAST="IEA*1*" +... (4 Replies)
Discussion started by: billy5
4 Replies

10. Shell Programming and Scripting

AWK Syntax errors :/

I recently started as an intern and my manager wanted to see how well I would handle Korn Bourne shell scripting without any prior experience, I have prior programming experience but I keep running into syntax errors with AWK. Please take a look at my simple code and tell me what stupid mistake... (6 Replies)
Discussion started by: yongho
6 Replies
Login or Register to Ask a Question