Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find More Than 9 Files With This Script

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
The below script creates pre_build files for as many files* it finds in the directory. The problem is that if there are more than 9 files it stops. How can I make it keep going? Sometimes there may be different amounts.

#!/bin/ksh

for i in *file*
do
outFile=$(echo ${i} | sed -e 's/.*\([0-9][0-9]*\)$/pre_build\1/g');
# echo "file->[${i}] outFile->[${outFile}]"
cat pre_master_build > ${outFile}
done;
 
The script looks ok to me. Remove the # in front of the echo and post the results. CaKiwi
 
Hey CaKiwi thanks for stepping in!

bham_mta@wepmas1> master.pre_build.sh
file->[file1] outFile->[pre_build1]
file->[file10] outFile->[pre_build0]
file->[file11] outFile->[pre_build1]
file->[file12] outFile->[pre_build2]
file->[file13] outFile->[pre_build3]
file->[file14] outFile->[pre_build4]
file->[file15] outFile->[pre_build5]
file->[file16] outFile->[pre_build6]
file->[file17] outFile->[pre_build7]
file->[file18] outFile->[pre_build8]
file->[file19] outFile->[pre_build9]
file->[file2] outFile->[pre_build2]
file->[file20] outFile->[pre_build0]
file->[file21] outFile->[pre_build1]
file->[file22] outFile->[pre_build2]
file->[file23] outFile->[pre_build3]
file->[file24] outFile->[pre_build4]
file->[file25] outFile->[pre_build5]
file->[file26] outFile->[pre_build6]
file->[file27] outFile->[pre_build7]
file->[file28] outFile->[pre_build8]
file->[file29] outFile->[pre_build9]
file->[file3] outFile->[pre_build3]
file->[file4] outFile->[pre_build4]
file->[file5] outFile->[pre_build5]
file->[file6] outFile->[pre_build6]
file->[file7] outFile->[pre_build7]
file->[file8] outFile->[pre_build8]
file->[file9] outFile->[pre_build9]
 
I changed it to

outFile=$(echo ${i} | sed -e 's/.*\([0-9]+\)$/pre_build\1/g');

which seems to work, but I don't understand why the original does not work. CaKiwi
 
Sorry, I was too hasty. That doesn't work. I'm still looking. CaKiwi
 
ooops, sorry - I'm bad ;)

#-------------------------------------------------------
#!/bin/ksh

for i in *file*
do
outFile=$(echo ${i} | sed -e 's/[^0-9]*\([0-9][0-9]*\)$/pre_build\1/g');
#echo "file->[${i}] outFile->[${outFile}]"
cat pre_master_build > ${outFile}
done;
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
I get this back....

for: Command not found
do: Command not found
Variable syntax
bham_mta@wepmas1>
 
Nevermind I'm stupid! I forgot to take out:

#-------------------------------------------------------


:)

Thanks for the help Vlad and CaKiwi!
 
Or to do it all in ksh:

#---------------------------------------------
#!/bin/ksh

for i in *file*
do
#outFile=&quot;${i##*[!0-9]}&quot;
#echo &quot;file->[${i}] outFile->[${outFile}]&quot;
cat pre_master_build > &quot;pre_build${i##*[!0-9]}&quot;
done;
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
I have not run this in awhile and it is not working now. Can you take a look and see if I am missing something?

#!/bin/ksh

for i in *file*
do
outFile=$(echo ${i} | sed -e 's/[^0-9]*\([0-9][0-9]*\)$/pre_build\1/g');
#echo "file->[${i}] outFile->[${outFile}]"
cat pre_master_build > ${outFile}
done;

I get the below response:

beaster@atappsrv20> /usr/bin/sh -v master.pre_build.sh
#!/bin/ksh

for i in *file*
do
outFile=$(emaster.pre_build.sh: syntax error at line 5: `outFile=$' unexpected
beaster@atappsrv20> /usr/bin/sh -v master.pre_build.sh
#!/bin/ksh

for i in *file*
do
outFile=$(emaster.pre_build.sh: syntax error at line 5: `outFile=$' unexpected
 
beaster,

The syntax you are using is not recognized by the bourne shell. Try running it using ksh -v master.pre_build.sh

John
 
I fixed the way I run this. I was running it as:

/usr/sh -v

Instead of

/usr/ksh -v

It works now.
 
Hey Beaster,

Welcome back, we've missed you! How are the rest of your scripts running?

CaKiwi
 
They are running awesome!

From the ones you guys have helped me out with, it has saved us thousands of man hours by not having to write DT to build cell rehome scripts manually!

Always much thanks!
Beaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top