If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Korn script expression syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-04, 12:08
heprox heprox is offline
Registered User
 
Join Date: Oct 2003
Posts: 54
Question Korn script expression syntax

I'm using a Korn script to rename some files using a simple function. Basically I have large set of files with the following format:

str####.asc.????? (example: str0002.asc.23154)

#### = a location number
????? = the PID of the process that created this file

...I want to rename these files to the following format:

upload.#### (example: upload.0002)

...and just loose the PID all together. I'm using the following syntax, but I still can't get it to only "grab" the location number:


while :
do
for fileName in /datafiles/str[0-9][0-9][0-9][0-9].asc.?????
do
fileExtension=${fileName#*.}
is_file_arrived "$fileName" && processFile $fileName $fileExtension
done
done

...can someone tell me the proper syntax for:

"fileExtension=${fileName#*.}"

...also how would I put in a check to see if the file that it was being renamed too, already exists?
Reply With Quote
  #2 (permalink)  
Old 05-10-04, 09:25
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You might be asking a bit much of the shell to get the location number this way. Try using sed...
Code:
fileName=str0002.asc.23154
locationNumber=$(echo $(basename ${fileName}) | sed 's/^.*\([0-9]\{4\}\)\..*/\1/')
To test if file exists use 'test -f fileName' or 'test -e fileName'.

HTH
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On