ksh Help with rename a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh Help with rename a file
# 1  
Old 01-09-2016
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..
# 2  
Old 01-09-2016
Am I missing something here? Why would one write a script:
Code:
#!/bin/ksh
mv FD_0069A59098374_0502112_060915.PDF FD_5A8Y6_069A59098374_0502112_060915.PDF

instead of just issuing the command:
Code:
mv FD_0069A59098374_0502112_060915.PDF FD_5A8Y6_069A59098374_0502112_060915.PDF

in a terminal session?
# 3  
Old 01-09-2016
Quote:
Originally Posted by Don Cragun
Am I missing something here? Why would one write a script:
Code:
#!/bin/ksh
mv FD_0069A59098374_0502112_060915.PDF FD_5A8Y6_069A59098374_0502112_060915.PDF

instead of just issuing the command:
Code:
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.
# 4  
Old 01-09-2016
Not too clear. How about
Code:
for FN in "FD*.PDF"; do echo mv $FN ${FN/FD/FD_5A8Y6}; done

? Remove echo when happy.
# 5  
Old 01-09-2016
Quote:
Originally Posted by RudiC
Not too clear. How about
Code:
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..
# 6  
Old 01-09-2016
Try ${FN/FD/FD$PARAM1}
This User Gave Thanks to RudiC For This Post:
# 7  
Old 01-09-2016
Quote:
Originally Posted by RudiC
Try ${FN/FD/FD$PARAM1}
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

2. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

4. Shell Programming and Scripting

rename file

Hi, I have files in the format thread_1_seq_1965.440.755943413 thread_1_seq_1966.577.755943443 thread_2_seq_2034.383.388388888 I want to rename this in the form of 1_1965.arc 1_1966.arc 2_2034.arc Discard everything except the th char and . The character position... (3 Replies)
Discussion started by: bang_dba
3 Replies

5. UNIX for Dummies Questions & Answers

look for specific values in a file and rename file with value found

Hi, i have a file with some data ..look for some specific value in the file and if found that value rename the file with the value found in the file.. ex.. File.txt 1236 43715825601ANDERSSON, 1236 437158256031963040120060901200609010000000 1236 43715825604123 MCCL AVE UPPER 1236 ... (11 Replies)
Discussion started by: dssyadav
11 Replies

6. Shell Programming and Scripting

ksh command to rename all files with no extension

hi! i want to rename all files with no extension with the extension DAT. with this command ls |grep -v "\\." i can list files but i dont know how i am going to rename them.. so i tried FILE_LIST=ls |grep -v "\\." for TEST_FILE in ${FILE_LIST} do mv $TEST_FILE... (2 Replies)
Discussion started by: kouppoua
2 Replies

7. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

8. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

9. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

10. UNIX for Dummies Questions & Answers

Help with multiple file rename - change case of part of file name

Hi there, I hope someone can help me with this problem : I have a directory (/var/www/file/imgprofil) which contains about 10000 JPG files. They have a naming convention thus : prefix-date-key-suffix.jpg they all have the prefix p-20050608- then AAAA is a 4 letter code the suffix is... (7 Replies)
Discussion started by: steve7
7 Replies
Login or Register to Ask a Question