![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sed to grep only numbers in string | ajilesh | Shell Programming and Scripting | 5 | 11-07-2008 01:39 PM |
| How to sort a string with numbers | ahjiefreak | Shell Programming and Scripting | 5 | 12-21-2007 10:52 AM |
| How to Compare Floating point / real numbers | padarthy | Shell Programming and Scripting | 13 | 09-24-2007 08:03 PM |
| How do i get numbers from a string? | eliraza6 | Shell Programming and Scripting | 13 | 07-18-2007 07:04 AM |
| problem with floating point numbers in awk | kanagias | Shell Programming and Scripting | 7 | 06-24-2005 03:14 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Using Floating Numbers in String
Dear Unix Gurus,
I have a list of files that I want to loop over....for example: Code:
sl40_z11.70.txt sl41_z11.40.txt sl42_z11.10.txt sl43_z10.80.txt Code:
#!/bin/sh # echo -n "....enter first Z-coordinate position....."; read zpos q="scale=3; $zpos" p=0.3 # loopNumber=$[($lastslice - $firstslice)+1] echo "loopNumber is $loopNumber" echo firstslice no. is $firstslice for ((i=$firstslice; i<=$loopNumber; i++)); do n=$[i] for ((k=0; k<=$loopNumber; k++)); do r=$[k] ; f=$r*$p ; zposition=$q-$f echo "sl$[n]_z$[zposition].txt" done done My problem is that the script works fine with the exception that bash doesn't recognize $zposition. It apparently can't handle iteration with floating numbers? Can someone help? Cheers |
|
||||
|
Quote:
Code:
echo "$zposition" |bc Code:
echo "sl$[n]_z$[zposition].txt" |
|
||||
|
Quote:
I revisited it too and scratched my head as well! There's a bug in the script...if firstslice is bigger than lastslice it won't work. So I've tried a different tack using awk. as a reminder, this is what I want to do; I have a list of files: Code:
sl40_z11.70.txt sl41_z11.40.txt sl42_z11.10.txt sl43_z10.80.txt Code:
cp sl40_z11.70.txt sl40_z11.70.dat cp sl41_z11.40.txt sl41_z11.40.dat cp sl42_z11.10.txt sl42_z11.10.dat cp sl43_z10.80.txt sl43_z10.80.dat my new script is : Code:
#!/bin/sh
#
echo -n "....enter first slice number....."; read firstslice
echo -n "....enter last slice number....."; read lastslice
#
echo -n "....enter first Z-coordinate position....."; read zpos
#sliceDiff=0.3
#
loopNumber=$[($lastslice - $firstslice)+1]
echo "loopNumber is $loopNumber"
echo firstslice no. is $firstslice
for ((k=$firstslice;k<=$lastslice; k++)); do
r=$[k]
echo "$firstslice $r $zpos" | awk '{print $3-(($2-$1)*0.3)}'
#echo "$firstslice $r $zpos" | awk '{print $i}' sl$2_z[$3-(($2-$1)*0.3)].txt > xxxx.dat
done
loops over the 4 files nicely. But I don't know how to incorporate the output into the last line of the script so that awk recognizes the filename. Any help would be much appreciated. Cheers |
| Sponsored Links | ||
|
|