ksh Help with rename a file

Hi,

I am new to KSH scripting and i am currently got struck with a issue. I am currently have files in the server live below

FD_0069A59098374_0502112_060915.PDF and i need to rename this to FD_5A8Y6_069A59098374_0502112_060915.PDF

can some one please help me with a KSH script which does this?

I appreciate any help..

Am I missing something here? Why would one write a script:

#!/bin/ksh
mv FD_0069A59098374_0502112_060915.PDF FD_5A8Y6_069A59098374_0502112_060915.PDF

instead of just issuing the command:

mv FD_0069A59098374_0502112_060915.PDF FD_5A8Y6_069A59098374_0502112_060915.PDF

in a terminal session?

Sorry for not being clear.. I have a unix script which does lots of steps in that sctipt one script generates PDF files and in other step I need rename them to add some additional information and rename the file with that additional info and i need to give those files to the third step.

I just gave one example.. i will not know the actual file name at the time of execution of script.. in the second step before the rename is called i perfom a find using this "069A5909837" value then I have the files in the list. Then i need to do the re-name to add "5A8Y6_069A59098374" in the file name. Hope this explains my issue.

Not too clear. How about

for FN in "FD*.PDF"; do echo mv $FN ${FN/FD/FD_5A8Y6}; done

? Remove echo when happy.

Please help me how i can achieve this with variables. In the run time i will the 2nd parameter in the new filename in a varables..
Examples
OldFileNme = FD_0069A59098374_0502112_060915.PDF
PARAM1 = _5A8Y6

I need a script which can inject PARAM1 in to the second parameter of the OldFileNme and rename..

Try ${FN/FD/FD$PARAM1}

1 Like

Thanks .. I will try and post the results.

---------- Post updated at 08:27 PM ---------- Previous update was at 07:53 PM ----------

Thanks a lot.. working great. You saved my day