Help with Kornshell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Kornshell Script
# 1  
Old 05-26-2009
Help with Kornshell Script

Hi,

I'm a novice at programming and need some help with a kornshell script I've been writting.

I have an inputdirectory with all my .shp files. In my input directory the shapefiles are named XXXX_original.shp, XXXX_UPDATE.shp ect.

In my .ksh script I have created a for loop which loops through all the files in the inputdirectory preforming a translation. Here is my code for my for loop.

for file in $InputDirectory/*.shp
do
*runs translation
done

This works fine, but I want to add a condition to my for loop. I only want my for loop to run when I have files which can be translated against each other. For example,

in my input directory I only want my loop to run when I have files XXXX_original.shp and XXXX_Update.shp ect. in the input directory.

I DO NOT want my for loop to run when I'm missing files. For example,

in my input directory I DO NOT want my loop to run when I have XXXX_original.shp and no corresponding XXXX_Update.shp. Or XXXX_Update.shp and NO XXXX_original.shp. Instead I could have a message box pop up with a message to the user.

Any help would be greatly appreciated.

Thanks,

Bryan
# 2  
Old 05-26-2009
Code:
cd $InputDirectory
for file in *_original.shp
do
    base=`basename $file _original.shp`
    if [ -e  ${base}_Update.shp ] 
    then
        *runs translation
    fi
done

# 3  
Old 05-27-2009
Thanks for the response Jerry,

My problem seems to run deeper,

I have a directory called shp_mslinks, with a series of files, lets say;

XXXX_original.shp
XXXX_UPDATE.shp
YYYY_original.shp
YYYY_UPDATE.shp
ZZZZ_original.shp
ZZZZ_UPDATE.shp
ect.

I also have a do loop which will preform a transformation on each file in the shp_mslinks directory, my loop;

# enter do loop and translate each shp file in the InputDirectory

for file in $InputDirectory/*.shp
do
# strip off path
fname=${file##*/}
# strip off extention
fname=${fname%.*}
print |tee -a -i $WorkingDirectory/change.txt
print "translating $fname.shp from shape to shape" |tee -a -i $WorkingDirectory/change.txt
print "======================" |teje -a -i $WorkingDirectory/change.txt

# run translation program
done

The problem is is only runs the transformation on the _original.shp files in the shp_mslinks directory and I want it to run on both the _original.shp and _UPDATE.shp

Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[KornShell]: Why getopts doesn't detect disabled switches in this script?

Hi, My environement OS: Linux Fedora Core 17 X86_64 KSH version: sh (AT&T Research) 93u+ 2012-08-01 As I understand inside a Kornshell script, the getopts statement allows to collect information about the switches provided for the script (if any). Besides, it is possible to... (3 Replies)
Discussion started by: dariyoosh
3 Replies

2. Shell Programming and Scripting

Kornshell Using a variable in a command

So Here is my code cd $cer_mgr table='hostname' environment='echo $environment' cat mq_$table_$environment_startup.ksh I'm trying to make the results of the command "hostname" into a variable so that i can use it in my cat command. Well what I have is not working. So how do I use that... (1 Reply)
Discussion started by: Blogger11
1 Replies

3. Shell Programming and Scripting

Kornshell grabbing value from file

I have a script right now that I run a command which outputs just one word to a file. Well I need to grab that value and use it in another line of code so... touch oraclesid.txt echo $ORACLE_SID > oraclesid.txt #grab that value sqlplus v500/v500@<value> how do I grab that value from the... (6 Replies)
Discussion started by: Blogger11
6 Replies

4. Shell Programming and Scripting

write a perl script or kornshell reading a two files and outputting to comma format

Hello Can someone help me to write a perl script or kornshell reading a two files and outputting to comma format. Here is the two files listofdisks.txt id, diskname, diskgroup, diskisze(GB), FC 1, CN34, GRP1, 30, FC_CN34 2, CN67, GRP5, 19, 4, VD1, GRP4, 23, FC_VD1 6, CF_D1, ... (0 Replies)
Discussion started by: deiow
0 Replies

5. Shell Programming and Scripting

How to make a script (Bash, KornShell, etc.) executable by mouse clicking?

Hello everybody, Is there any way to make a script (Bash, KornShell, etc.) executable by mouse clicking? For example you have a file myscript.sh, you run: $ chmod u+x myscript.sh Therefore it becomes executable and all you need is to run from the terminal: $./myscript.sh... (2 Replies)
Discussion started by: dariyoosh
2 Replies

6. Shell Programming and Scripting

help with Kornshell function

I am trying to write a Kornshell function that takes a string parameter which represents a filename or directory name. The function checks to see if there are any spaces in the filename or directory name and then replaces the spaces with an underscore. The returned value is a filename or directory... (1 Reply)
Discussion started by: ckrieger1
1 Replies

7. Shell Programming and Scripting

Need Help with KornShell script

I need a KornShell script that will, among all the users currently logged on to the system, find a slot of one hour that contains the most number of users. I know how to list all the users currently logged on but how do I do anything with the times that are listed? Please help, thanks. (1 Reply)
Discussion started by: ckrieger1
1 Replies

8. Programming

Kornshell convdate

Hello, I'm currently doing some programming using the Kornshell environment. I have just been on a Unix course where our instructor gave us some coding examples. I am using one of these examples to solve a few problems. However, the code examples use a function called 'convdate' to convert a... (10 Replies)
Discussion started by: nezster
10 Replies

9. UNIX for Advanced & Expert Users

mailx in kornshell script passing return code to CA-Unicenter

I have a KornShell script that has successfully been scheduled through Cron. We are in the process of changing over from Cron to using CA-Unicenter. To negative test the script I put a bad return code in. At the bottom of the script an e-mail is sent using mailx and then the return code is set... (1 Reply)
Discussion started by: Connie
1 Replies

10. UNIX for Dummies Questions & Answers

Kornshell 93

I've been asked to upgrade from Kornshell 88 to Kornshell 93 on a Solaris 7 box. Since my experience with Unix is limited can anyone point me in the right direction? Specifically, where can I get the files that I need to do the upgrade? Thanks. (1 Reply)
Discussion started by: Ask Me
1 Replies
Login or Register to Ask a Question