![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| create a thread from a returning function | wolwy_pete | High Level Programming | 3 | 05-08-2008 12:48 AM |
| create function with awk | kamel.seg | Shell Programming and Scripting | 2 | 12-24-2007 02:36 PM |
| sqrt is not find??? | murataht | High Level Programming | 2 | 10-17-2004 07:04 AM |
| create thread C with JNI function with JAVA | AUBERT | HP-UX | 0 | 08-06-2004 02:24 AM |
| sqrt | CreamHarry | High Level Programming | 1 | 06-03-2002 04:56 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to create SQRT function in catenate file
HI,
I have a file which i catenate and using the fields in the file, I would like to get sqrt of it. I tried to man the function but it normally would need an echo as well as bc. What I am intending to find out is catenate a file where let say cat a.txt| awk ' { t= h*($3+$2); t= 'sqrt($t)' | bc -l count($1)=$2/t } END{ printf("the sqrt of %d is %d\n", $2,$1); } However, it does not work. Please help. Thanks. Rgrds, Jason |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Quote:
Why cannot you use awk's 'sqrt'? Quote:
|
|
#3
|
|||
|
|||
|
Hi ,
Do you mean using the same code that I described earlier on? Please advise. Thanks. -Jason |
|
#4
|
||||
|
||||
|
Quote:
What I mean (for starters) why cannot use awk's "sqrt" built-in function? I guess I don't understand:
|
|
#5
|
|||
|
|||
|
Hi,
The answer to this question is:- 1. what "t=sqrt($t)' | bc -l " is supposed to do 2. what is the value of 'h' in "t= h*($3+$2);" I am basically trying to get an operation of two fields of columns $3 and $2 with multiplication of some constant value(h). These operation will end up giving me a number which is t. Then, this t value I would like to get its square root and assign to a new variable. Perhaps I should write as "w=sqrt($t)" |bc -l in the first place. 3. What do think the value of $2 and $1 will be in the 'END' block 4. what's the intent of this: count($1)=$2/t I would like to divide again the field of column 2 with the square root value to associate with field $1. Basically in my case, $1 is unique line number and $2 is just a numeric value for each line in the file a.txt. 5. why are you doing this 'cat a.txt' The cat a.txt is bascially I would like to open the file which contains all the numbers and have 3 fields; $1, $2 and $3. -Jason |
|
#6
|
||||
|
||||
|
Quote:
What do you think the value of '$t' in 'sqrt($t)' is? Why are you trying "pipe" 'sqrt($t)' into 'bc -l'? Wouldn't a simple 't=sqrt(t)' be enough? Quote:
DO mean you want to use the associative array indexed by the value of your FIRST '$1' column? Something like that: Code:
countArray[$1] = $2/t Quote:
Code:
awk '... awk BODY...' myInputFile. Last edited by vgersh99; 12-10-2007 at 12:18 AM. |
|
#7
|
|||
|
|||
|
Hi
Where the 'constant' (h) gets assigned it's value? The h is actually counting the number of folders from other variables. What do you think the value of '$t' in 'sqrt($t)' is? Why are you trying "pipe" 'sqrt($t)' into 'bc -l'? Wouldn't a simple 't=sqrt(t)' be enough? Yeah. I already tried on sqrt(t); which is without bc -l. You are right. I am using associative array count for the purpose to read each line. However, when I get the result from the operation, it doesnt return me the correct output from these operation.Did I missed out any "$" in the below fragment of code? It gives me INF and NAN value cat a.txt| awk ' { t= h*($3+$2); s= sqrt($t) count($1)=$2/s } END{ printf("the sqrt of %d is %d\n", $2,$1); } Please advise.Thanks. Rgrds, Jason |
|||
| Google The UNIX and Linux Forums |