Sponsored Content
Top Forums Shell Programming and Scripting How to create SQRT function in catenate file Post 302150061 by vgersh99 on Monday 10th of December 2007 02:05:02 AM
Old 12-10-2007
Quote:
Originally Posted by ahjiefreak
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.
Where the 'constant' (h) gets assigned it's value?
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:
Originally Posted by ahjiefreak
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.
'count($1)' looks like a function 'count' taking a parameter with value of '$1'. And you're assigning '$2/t' to the function. This does not make any sense.
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:
Originally Posted by ahjiefreak
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
The general awk paradigm for 'reading' files is:
Code:
awk '... awk BODY...' myInputFile.


Last edited by vgersh99; 12-10-2007 at 03:18 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

sqrt

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

2. 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

3. 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

4. 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

5. 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

6. 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 quadratic-eqn-roots.sh 9 quadratic-eqn-roots.sh: line 12: ( (... (6 Replies)
Discussion started by: srinivas2828
6 Replies

7. 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

8. 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

9. 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

10. Programming

A Function To Create A 1 Second Sinewave WAVE Beep File In Python.

sinebeep.py 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
EV(1)							      General Commands Manual							     EV(1)

NAME
ev - evaluate expressions SYNOPSIS
ev 'expr' .. DESCRIPTION
Ev evaluates expressions given on the command line, and sends the results to the standard output, one per line. An expression contains real numbers, function calls, and the following operators: + - * / ^ Operators are evaluated left to right, except '^', which is right associative. Powers have the highest precedence; multiplication and division are evaluated before addition and subtraction. Expressions can be grouped with parentheses. All values are double precision real. The following library of functions is available: if(cond, then, else) if cond is greater than zero, then is evaluated, otherwise else is evaluated. select(N, a1, a2, ..) return aN (N is rounded to the nearest integer). If N is zero, the number of available arguments is returned. rand(x) compute a random number between 0 and 1 based on x. floor(x) return largest integer not greater than x. ceil(x) return smallest integer not less than x. sqrt(x) return square root of x. exp(x) compute e to the power of x (e approx = 2.718281828). log(x) compute the logarithm of x to the base e. log10(x) compute the logarithm of x to the base 10. sin(x), cos(x), tan(x) trigonometric functions. asin(x), acos(x), atan(x) inverse trigonometric functions. atan2(y, x) inverse tangent of y/x (range -pi to pi). EXAMPLE
To pass the square root of two and the sine of .5 to a program: program `ev 'sqrt(2)' 'sin(.5)'` AUTHOR
Greg Ward SEE ALSO
icalc(1), rcalc(1) RADIANCE
10/28/96 EV(1)
All times are GMT -4. The time now is 01:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy