The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 07-06-2009
tintin72 tintin72 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 23
Quote:
Originally Posted by fpmurphy View Post
Humm, I have looked at this shell script a few times and scratched my head.

You set the variable 'q' to a string

Code:
q="scale=3; $zpos"

yet you expect to be able to subtract a number from it

Code:
zposition=$q-$f

How is this meant to work?
Hi,

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

I want to loop through these files keeping their labelling intact. For example, I want to do in a single script


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

I have hundreds of these files and I need to carry out other non-trivial operations on them. Problem is bash does not recognize floating numbers so I can't loop over them.

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

So running this script and entering at prompts "40" , "43", "11.70"
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