Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Posts
    54

    Question Unanswered: 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?

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •