LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2012, 12:01 AM   #1
Perseus
Member
 
Registered: Oct 2011
Posts: 179

Rep: Reputation: Disabled
Modify name of file that are inside zip file


Hello to all in forum,

I'm using unzip command to decompress the file MyFile.zip that contains several files inside of it named with this format.

"MyFile_"+"Other string"+"extension".

Example:
Code:
MyFile_plan2012.log
.
.
.
MyFile_my_resources.pdf
I would like to extract the files modifying the name by deleting the "MyFile_" at the beginning of each file.
There could be more than one "_", but only is needed to erase the text before the first "_" and the first "_" itself.

The unzipped files should be stored in a folder called MyFile and will look like these:

Code:
plan2012.log
.
.
.
my_resources.pdf
"MyFile" is the name and may contain spaces.

May somebody help me to get this output.

Thanks in advance.

PS: I'm using cygwin.

Greetings.
 
Old 02-07-2012, 06:18 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
The commands you would need would be "rename" (or you could use a 'for' loop with 'ls' and 'mv'), "unzip", "mkdir", and (maybe) "cd".

Have you tried putting any of these commands together?

The flow of commands you'd be looking at is:

Code:
make "MyFile" directory
Unzip contents of MyFile.zip into MyFile directory
Rename all the files in MyFile directory that begin with "MyFile_"
        so that they don't begin with it
Hope this helps,
 
Old 02-07-2012, 07:50 PM   #3
Perseus
Member
 
Registered: Oct 2011
Posts: 179

Original Poster
Rep: Reputation: Disabled
Hey,

Thank you Snark1994 for answer.

I've used exactly those commands and within some for loops and it seems to work.

I was stuck with the regex in how to replace the names, but a bash option (${var#*_}) helped me
to avoid find the correct regex.

Thank you again.

Regards
 
Old 02-08-2012, 04:03 PM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Well done!

If you have no further (related!) questions, could you mark this thread as 'SOLVED' please?

Thanks,
 
Old 02-08-2012, 05:28 PM   #5
Perseus
Member
 
Registered: Oct 2011
Posts: 179

Original Poster
Rep: Reputation: Disabled
Hello Snark,

Of course, simply I can't find the option to do that, is not in thread tools.

Regards
 
Old 02-09-2012, 08:07 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Are you sure? :S There's normally a link at the top of the page as well, above the "Post Reply" button...
 
Old 02-09-2012, 03:06 PM   #7
Perseus
Member
 
Registered: Oct 2011
Posts: 179

Original Poster
Rep: Reputation: Disabled
Hi again snark,

I'm sure. Yesterday I logged twice and the options to mark as solved werent present for me nor within thread tools nor above post reply button.

Today after my login I could see both options how usually they appear and the thread was marked as solved.

Best regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find out a file in a WAR which in a zip without unzip the zip-file? thomas2004ch Linux - Software 3 09-30-2011 03:06 PM
Script to traverse into sub-directory and replace line of file inside zip Marshalle Linux - General 2 08-27-2010 11:38 PM
How to modify a field in few lines in a file and save the new file - in Perl rounak94 Programming 1 10-02-2008 07:43 PM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 01:50 AM
modify file access & modify timestamps i2itstud Linux - General 1 05-20-2003 03:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration