How to create SQRT function in catenate file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create SQRT function in catenate file
# 8  
Old 12-10-2007
Originally Posted by ahjiefreak
Where the 'constant' (h) gets assigned it's value?
The h is actually counting the number of folders from other variables.
No, it's not. h is doing nothing. You never assign it a value. awk will initialize it to zero for you. So that is the only value it ever has.

Originally Posted by ahjiefreak
Did I missed out any "$" in the below fragment of code?
Miss out?? You have too many!
$ awk -v h=64  'BEGIN { print sqrt(h); }' /dev/null
$ awk -v h=64  'BEGIN { print sqrt($h); }' /dev/null

In the code:
t= h*($3+$2);
s= sqrt($t)

t will be zero since you guaranteed that h is zero.
would have taken the square root of that zero and yielded zero, a legal operation.
is going to try the square root of $0, the whole record in awk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

A Function To Create A 1 Second Sinewave WAVE Beep File In Python. Creating an audio WAVE file called... beep.wav ...that can be played using almost ANY audio player available. This simple DEMO snippet of code generates a 1 second sinewave WAVE file. It IS saved inside the CURRENT drawer so that you can find it... ;o) Note that the... (1 Reply)
Discussion started by: wisecracker
1 Replies

2. Shell Programming and Scripting

Create function

I would like to make a perl function , this function could send mail via SMTP and also could import a text file into mail content , that mean I have a text file , want to use this function to send mail via SMTP , the mail content is the text file , would advise how to write this script ? thanks (1 Reply)
Discussion started by: ust3
1 Replies

3. Shell Programming and Scripting

How to create .txt file by using function?

My Calling script is like below: for file in `echo $LIST_OF_FILES` --listing filenames eg, xyz_meta_20110501_00000789.tar do file_name=`basename $file` <call a function to create .txt file in below format> done Want to generate a .txt file that contains below data in ksh: ... (3 Replies)
Discussion started by: vedanta
3 Replies

4. UNIX for Dummies Questions & Answers

sqrt in bash

Hi, i have a the following script: #!/bin/bash a=3 b=9 let "c= b*a" let "d=sqrt $c " echo $d But when i execute the code, it gives me the an error saying: line 5: let: d=sqrt 27 : syntax error in expression (error token is "27 ") Can any body tell me what I'm doing wrong? (5 Replies)
Discussion started by: limadario
5 Replies

5. Shell Programming and Scripting

how can i find sqrt of a any number without using expr

hi friends can any body tell me how can i find sqrt of a any given number without using expr in bash shell while i am doing i got some errors please take a look and code is here x=$((( ( sqrt($1) ) | bc ))) echo $x $ sh 9 line 12: ( (... (6 Replies)
Discussion started by: srinivas2828
6 Replies

6. UNIX for Dummies Questions & Answers

How to create alias for a function

Hi, In Unix (AIX/LINUX) how do we create a alias for a UNIX shell function? Please help me with that. Thanks!! (2 Replies)
Discussion started by: neeto
2 Replies

7. Programming

create a thread from a returning function

hi all, my requirement is to create a thread by calling another function. i.e i dont call pthread_create directly from main, but by calling another function (createThd - below ), from main. Example: void *thread_function(void *arg) { /* thread function */ int i; rc =... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

8. Shell Programming and Scripting

create function with awk

hi all, i print four variable delimited by comma with awk : awk -F "," '{print $1;$2;$3;$4}' ' if $3="" code ... } i want to extract this information from another file using another awk using the $1 printed awk -v { code } but the problem i can't use two awk in the same code... (2 Replies)
Discussion started by: kamel.seg
2 Replies

9. Programming

sqrt is not find???

I was writing a simple program in linux, which includes sqrt function of c. I included the math.h. But when I use gcc to compile it, it gave an error message: /home/murat/tmp/ccOv9upo.o(.text+0x4b): In function `main': : undefined reference to `sqrt' collect2: ld returned 1 exit status I... (2 Replies)
Discussion started by: murataht
2 Replies

10. Programming


Hi! when i'm trying to compile this lite example on my linux machine I'll get errors and i don't know why.. #include <stdio.h> #include <math.h> /* needed by sqrt() */ int main() { printf("%f", sqrt(10.0)); return (0); } this is the error: /tmp/cc33hNVHK.o: In function... (1 Reply)
Discussion started by: CreamHarry
1 Replies
Login or Register to Ask a Question