Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-06-2012
Registered User
 

Join Date: Oct 2011
Posts: 59
Thanks: 8
Thanked 1 Time in 1 Post
Rename files that are inside zip file

Hello to all,

I have a zip file with any name like FileName.zip, within the zip file there are more than 30 files with different extensions in the following format.

Code:
FileName_BMN_ROSJ.txt
FileName_THEUS.jpg
.
.
.
FileName_KWPWP.shx

I would like to unzip the file and rename each file inside removing the first part "FileName_" thinking that "FileName" could have spaces.

The unzipped files must be named as below:

Code:
BMN_ROSJ.txt
THEUS.jpj
.
.
.
KWPWP.shx

May somebody help with this.

Any help will be appreciated.

Greetings
Sponsored Links
    #2  
Old 02-07-2012
Registered User
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 1,203
Thanks: 56
Thanked 98 Times in 96 Posts

Code:
while read file
do
 echo mv $file ${file#*_}
done < file_contains_list_of_filename


Test, verify and then remove the "echo".
Sponsored Links
    #3  
Old 02-07-2012
Registered User
 

Join Date: Oct 2011
Posts: 59
Thanks: 8
Thanked 1 Time in 1 Post
Hi anchal_kare,

Thank for your reply.

I wasn't able to get the correct regex to use within sed to rename the files, but using that bash option "${fname#*_}" was the way I could do it unzipping first the file and then renaming each file inside the zip.

Thanks again.

Greetings
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Rename files with tag in a .xml file crusty Shell Programming and Scripting 4 01-25-2012 06:55 AM
Rename the files with .xls file murari83.ds Shell Programming and Scripting 6 07-20-2011 02:00 PM
Script to rename zip-files with name of file mark_a17 Shell Programming and Scripting 7 05-11-2010 05:09 AM
awk a text file, use loop to copy files, rename file manouche Shell Programming and Scripting 3 04-12-2010 02:05 PM
Rename contents inside multiple files Lucky Ali Shell Programming and Scripting 6 02-16-2010 12:12 PM



All times are GMT -4. The time now is 04:30 AM.