Sponsored Content
Full Discussion: script to iterate
Top Forums Shell Programming and Scripting script to iterate Post 302561537 by Tytalus on Tuesday 4th of October 2011 11:29:14 AM
Old 10-04-2011
something along the lines of:

Code:
(rewriting your equation to isolate an iteration:

x=y/ln(3.455613x)
)

#  y=1;x=1;for i in {1..100}; do x=$(calc "$y/(log(3.455613*$x))"); echo $x;done
0.806452
0.975715
.
<snip>
.
0.890054
0.890054

where I have calc as a function:

#  typeset -f calc
calc ()
{
    nawk 'BEGIN { OFMT="%f"; print '"$*"'; exit}'
}

In this case, then:

#  calc "log(0.890054)"+1.24
1.123527

#  calc 1/0.890054
1.123527

You may prefer to define an epsilon value and check the diff between successive iterations to define your accuracy.

HTH

This User Gave Thanks to Tytalus For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

iterate sed over files

Greetings. I'm having a time of it with this file. I'm trying to do a script that will take two command line inputs, string1 and string2 and use sed to change the text over files in the current directory. This is what I have so far. It appears to work a little, it does create the... (3 Replies)
Discussion started by: rdanda
3 Replies

2. Shell Programming and Scripting

iterate over array

I can not for the life of me figure out how to iterate over this array { 'name1' => { 'a' => . 'b' => }, 'name2' => { 'a' => . 'b' => } } I want a for loop to iterate through the first element (name1 and name2 in my example) but I can't figure it out. Help... (2 Replies)
Discussion started by: IMTheNachoMan
2 Replies

3. UNIX for Dummies Questions & Answers

Iterate a min/max awk script over time-series temperature data

I'm trying to iterate a UNIX awk script that returns min/max temperature data for each day from a monthly weather data file (01_weath.dat). The temperature data is held in $5. The temps are reported each minute so each day contains 1440 temperature enteries. The below code has gotten me as far as... (5 Replies)
Discussion started by: jgourley
5 Replies

4. Shell Programming and Scripting

Shell - How to iterate through all the files in a directory?

Hi, I have a directory call Test, which contains files "a", b", "c", etc. I want to go through all of the files inside Test and remove any empty file. How would I do that with shell csh? So far I got... #!/bin/csh if (($#argv == 0) || ($#argv > 1)) then echo "no argument or too... (2 Replies)
Discussion started by: teiji
2 Replies

5. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

6. UNIX for Dummies Questions & Answers

Script to iterate all command line arguments

Hi guys, I am having trouble with this script. What i want it to do is to iterate all command line arguments in reverse order. The code below does this fine but i need the output to print the words on separate lines instead of one line: #!/bin/bash #Takes in the arguments and displays them... (7 Replies)
Discussion started by: pipeline2012
7 Replies

7. Shell Programming and Scripting

Do loop doesn't iterate

I'm trying to send the file list as parameter to another job and execute it. But the loop doesn't work, the inner job is running only once and not twice as expected for filelist in $(ls -rt *.txt | tail -2) do echo $filelist export filelist cmd="$Program -config $configfile -autoexec... (11 Replies)
Discussion started by: asandy1234
11 Replies

8. Shell Programming and Scripting

Iterate column with perl

I can not figure out how to iterate a perl command that inputs a value into columns and then combines them. I need to put a numerical value in column one and the word "Null" in all others, and then join at the end. I think the below is close, but I am not sure about the lines in bold. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

9. UNIX for Beginners Questions & Answers

Script to iterate over several options

Have two 3 files which has list of servers,users and location and base url which is common on every server A = server1 server2 server3 B = user1 user2 user3 C = dom1 dom2 dom3 baseurl=/opt/SP/ and what i have to achieve is below via ssh from REMOTE SERVER for it's first iteration it... (7 Replies)
Discussion started by: abhaydas
7 Replies

10. Shell Programming and Scripting

Iterate over `dirs` in a bash script

I would like to iterate over `dirs`in a script, but the script will never show more than one (current) folder #! /bin/bash for i in `dirs` do echo ${i} done echo ++++++++++++++++++ for i in $( dirs -p ) do echo ${i} done echo ------------------ dirscontent=`dirs` echo... (5 Replies)
Discussion started by: alexanderb
5 Replies
Math::BaseCalc(3pm)					User Contributed Perl Documentation				       Math::BaseCalc(3pm)

NAME
Math::BaseCalc - Convert numbers between various bases VERSION
version 1.016 SYNOPSIS
use Math::BaseCalc; my $calc = new Math::BaseCalc(digits => [0,1]); #Binary my $bin_string = $calc->to_base(465); # Convert 465 to binary $calc->digits('oct'); # Octal my $number = $calc->from_base('1574'); # Convert octal 1574 to decimal DESCRIPTION
This module facilitates the conversion of numbers between various number bases. You may define your own digit sets, or use any of several predefined digit sets. The to_base() and from_base() methods convert between Perl numbers and strings which represent these numbers in other bases. For instance, if you're using the binary digit set [0,1], $calc->to_base(5) will return the string "101". $calc->from_base("101") will return the number 5. To convert between, say, base 7 and base 36, use the 2-step process of first converting to a Perl number, then to the desired base for the result: $calc7 = new Math::BaseCalc(digits=>[0..6]); $calc36 = new Math::BaseCalc(digits=>[0..9,'a'..'z']); $in_base_36 = $calc36->to_base( $calc7->from_base('3506') ); If you just need to handle regular octal & hexdecimal strings, you probably don't need this module. See the sprintf(), oct(), and hex() Perl functions. METHODS
o new Math::BaseCalc o new Math::BaseCalc(digits=>...) Create a new base calculator. You may specify the digit set to use, by either giving the digits in a list reference (in increasing order, with the 'zero' character first in the list) or by specifying the name of one of the predefined digit sets (see the digit() method below). If your digit set includes the character "-", then a dash at the beginning of a number will no longer signify a negative number. o $calc->to_base(NUMBER) Converts a number to a string representing that number in the associated base. If "NUMBER" is a "Math::BigInt" object, "to_base()" will still work fine and give you an exact result string. o $calc->from_base(STRING) Converts a string representing a number in the associated base to a Perl integer. The behavior when fed strings with characters not in $calc's digit set is currently undefined. If "STRING" converts to a number too large for perl's integer representation, beware that the result may be auto-converted to a floating-point representation and thus only be an approximation. o $calc->digits o $calc->digits(...) Get/set the current digit set of the calculator. With no arguments, simply returns a list of the characters that make up the current digit set. To change the current digit set, pass a list reference containing the new digits, or the name of a predefined digit set. Currently the predefined digit sets are: bin => [0,1], hex => [0..9,'a'..'f'], HEX => [0..9,'A'..'F'], oct => [0..7], 64 => ['A'..'Z','a'..'z',0..9,'+','/'], 62 => [0..9,'a'..'z','A'..'Z'], Examples: $calc->digits('bin'); $calc->digits([0..7]); $calc->digits([qw(w a l d o)]); If any of your "digits" has more than one character, the behavior is currently undefined. QUESTIONS
The '64' digit set is meant to be useful for Base64 encoding. I took it from the MIME::Base64.pm module. Does it look right? It's sure in a strange order. AUTHOR
Ken Williams, ken@forum.swarthmore.edu COPYRIGHT
This is free software in the colloquial nice-guy sense of the word. Copyright (c) 1999, Ken Williams. You may redistribute and/or modify it under the same terms as Perl itself. SEE ALSO
perl(1). perl v5.12.3 2011-05-16 Math::BaseCalc(3pm)
All times are GMT -4. The time now is 05:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy