LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Replacing numbers in bash scripts (http://www.linuxquestions.org/questions/programming-9/replacing-numbers-in-bash-scripts-810052/)

bluesmodular 05-25-2010 02:49 PM

Replacing numbers in bash scripts
 
Hi,

I have lines in some files that look exactly as below, and the line numbers they occur in are always the same. (Lines 136-139)

W 0.00000000 0.00000000 2.00000000
W 0.50000000 0.50000000 2.50000000
W 0.00000000 0.00000000 3.00000000
W 0.50000000 0.50000000 3.50000000

I'd like to replace the last number in each row for each file by numbers related to the variable $vacheight, so that the median of these 4 numbers is always half of $vacheight.

The files are all named "run_example", but are in different folders named "examples#" where # is a number from 140 to 199.

As a related example, Line 117 reads:
Code:

  celldm(3)  = 5.000,
Below is the relevant section of code that works for Line 117 and increments the number on Line 117 by 0.1 each time, in a different folder.

Code:

vacheight=`expr 4.500`
for i in */run_example; do
    printf '117s/= [^,]*/= %s/\nwq\n' "$vacheight" | ed -s "$i"
    vacheight=$(echo "scale=3; $vacheight + 0.100" | bc)
done

Thank you very much for your help!

grail 05-26-2010 01:04 AM

Quote:

I'd like to replace the last number in each row for each file by numbers related to the variable $vacheight, so that the median of these 4 numbers is always half of $vacheight.
Not sure I understand this line (been a little while since at school), but are you suggesting we need the total of the four numbers and then the related sum has a median
equal to half of the vacheight value?


All times are GMT -5. The time now is 02:35 PM.