Shell Script Help..Renaming Quoted files removing the timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Help..Renaming Quoted files removing the timestamp
# 1  
Old 11-04-2015
Shell Script Help..Renaming Quoted files removing the timestamp

Hi all,

i am new to this forum, unix and shell scripting.

I would really appreciate if you all can help me here..

I have files coming in the below format

Code:
'filename20513'13May06:03:45

filename are characters..

like 'ABDDUT20513'13May06:03:45

i need it to be renamed as 'ABDDUT20513'

i tried
Code:
mv \'*\'${date}*  \'*\'

but its not working..

Help will be very much appreciated...

Thanks & Regards,
khman
Moderator's Comments:
Mod Comment As noted in later posts, it is not clear from the text provided by the original poster whether or not the single quotes are literal characters in the mentioned filenames. The single quotes provided by the OP have been preserved when CODE and ICODE tags were added.

Last edited by Don Cragun; 11-04-2015 at 11:14 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 11-04-2015
Please use code tags as required by forum rules!

Are you sure those single quotes are part of the file name? If not, and with a recent shell, try (untested)
Code:
echo mv $FN ${FN%${FN#*20513}}

with FN a shell variable holding the file name.
# 3  
Old 11-04-2015
Quote:
Originally Posted by khman
Hi all,

i am new to this forum, unix and shell scripting.

I would really appreciate if you all can help me here..

I have files coming in the below format

'filename20513'13May06:03:45

filename are characters..

like 'ABDDUT20513'13May06:03:45

i need it to be renamed as 'ABDDUT20513'

i tried mv \'*\'${date}* \'*\'

but its not working..

Help will be very much appreciated...

Thanks & Regards,
khman
Code:
$ FN="'ABDDUT20513'13May06:03:45"

$ echo $FN ${FN%${FN##*\'}}
'ABDDUT20513'13May06:03:45 'ABDDUT20513'

# 4  
Old 11-05-2015
You could also try:
Code:
FN="'ABDDUT20513'13May06:03:45"
echo mv "$FN" "${FN%\'*}'"

which produces the output:
Code:
mv 'ABDDUT20513'13May06:03:45 'ABDDUT20513'

So, if you remove the echo, it should rename the file the way you want it.
# 5  
Old 11-05-2015
Thanks all for the reply & sorry for not using the code tags...
excuse me as I am just a beginner right now.. Smilie

However, i feel it doesnt work..
i will explain in more detail...


i first find the files by the date, lets say 13May in a particular directory and uncompress them
Code:
 gunzip \'*\'${date}*

Then I change the permission
Code:
 chmod 777 \'*\'${date}*

After this Step, lets say I get a file as
Code:
 'ABDDUT20513'13May06:03:45

. This is value which i see in the runnnig the script in debug mode
This piece of code picks up the file
Code:
 \'*\'${date}*

file name can be anything but format will be the same as above.

now dynamically i need to rename whatever file comes

so for e.g. if it is
Code:
 'ABDDUT20513'13May06:03:45

Then output has to be
Code:
 'ABDDUT20513'

Another example: Lets say file name is 'ABCCDT20515'15May05:17:38.Z

Then expected output is
Code:
 'ABCCDT20515'

.

This renamed file has to be placed in the same directory then.

Kindly help.

I really appreciate your replies and kindly bear with me.
I am just in learning stages of Shell scripting

Last edited by khman; 11-05-2015 at 11:03 AM.. Reason: Forgot to add something & Add code tags
# 6  
Old 11-05-2015
OK Let's get back to basics. You have been given suggestions that should work with any POSIX conforming shell.

What operating system are you using?

What shell are you using?
This User Gave Thanks to Don Cragun For This Post:
# 7  
Old 11-05-2015
Hi Don,

Kindly brief about % in code echo mv "$FN" "${FN%\'*}'"
Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and removing the old files and zipping the files using shell script

Hi, I am trying to removing the old files which were older than 10 days and same g zipping the files using the shell script. script was return as follows. find /jboss7_homes/JBOSS7/SKYLIV??/SKYLIV??_CRM/jboss-eap-7.0/standalone/log -mtime +10 -type f | xargs rm -f find /cer_skyliv??/log... (6 Replies)
Discussion started by: venkat918
6 Replies

2. Shell Programming and Scripting

Shell Script for renaming and moving Files - Easy?

Hey guys, ive been working on this for about 2hrs now - without any solution. At first I need to say I dont have skills in linux bash scripting, but I tried to use some codesnippets and manuals from google. What I want to do: I have different folders including 2 different filestypes with... (15 Replies)
Discussion started by: peter1337
15 Replies

3. UNIX for Dummies Questions & Answers

Renaming Multiple Files by removing characters

Hi I would like to rename Multiple files in a Unix Directory using Ksh Command. Eg ATT8-2011-10-01 00:00:00-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF needs to be renamed as ATT8-2011-10-01-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF Basically the time... (2 Replies)
Discussion started by: pchegoor
2 Replies

4. Shell Programming and Scripting

Need help in batch renaming files with bash shell script.

I have some 50+ files in the following format : abcd_vish_running_ZEBRA_20140818.dat_08-14-2014_23:08:23 abcd_vish_running_ZEB-RA_20140818.dat_08-14-2014_23:08:35 abcd_vish_running_ZEB_RA_20140818.dat_08-14-2014_23:08:37 abcd_vish_running_RI-NG_20140818.dat_08-14-2014_23:08:42... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

5. Shell Programming and Scripting

Renaming multiple files with a shell script

Hey guys, I'm really new to UNIX and shell scripting in general. For my internship I need to rename a bunch of files. Specifically, I need to change the first letter of each of the files to lowercase and I have to change the endings so they all basically look like "file_cone.jpg". I know I... (4 Replies)
Discussion started by: jjzieve
4 Replies

6. UNIX for Dummies Questions & Answers

Shell script which will sort all the files in a directory with the timestamp they were created

Team, Pls help writing a shell script which will sort all the files in a directory with the timestamp they were created. (like ls -lrt) (6 Replies)
Discussion started by: asappidi
6 Replies

7. Shell Programming and Scripting

Need help with shell script for moving/deleting/renaming files

Hi. I need help with a little script that will be used to move some files to their parent directory, delete the directory, rename one file in the parent directory and delete another, then continue to the next. Here's an example: /var/media/Music/Genesis/1970 album - Trespass (2008 Box -... (4 Replies)
Discussion started by: aflower
4 Replies

8. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

9. UNIX for Dummies Questions & Answers

Renaming Files using Shell Script

Hi Gurus, I have some files(all ending with .out as extension). Ex: aa1.out aa2.out aa3.out I would like to append each file with the current date to the end of the file so that they should become aa1_20090504.out. So I am using rename as follows: for i in path/aa* ; do mv $i... (5 Replies)
Discussion started by: asmfloyd
5 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question