The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make a script (Bash, KornShell, etc.) executable by mouse clicking? dariyoosh Shell Programming and Scripting 2 03-09-2009 01:44 PM
help with Kornshell function ckrieger1 Shell Programming and Scripting 1 04-12-2004 10:43 AM
Need Help with KornShell script ckrieger1 Shell Programming and Scripting 1 02-13-2004 10:34 AM
mailx in kornshell script passing return code to CA-Unicenter Connie UNIX for Advanced & Expert Users 1 04-23-2002 08:45 AM
Kornshell 93 Ask Me UNIX for Dummies Questions & Answers 1 07-12-2001 04:56 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-26-2009
beery beery is offline
Registered User
  
 

Join Date: May 2009
Posts: 5
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 (permalink)  
Old 05-26-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
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 (permalink)  
Old 05-27-2009
beery beery is offline
Registered User
  
 

Join Date: May 2009
Posts: 5
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.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:58 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0