LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-04-2013, 05:51 AM   #1
karan4141
LQ Newbie
 
Registered: Aug 2012
Posts: 14

Rep: Reputation: Disabled
Remove space from a zip file


Hi Team,

I have an requirment from functional pepole they have some zip file & want to unzip this file & thn remove space from tge file name & than zip this file again.
For Example:- I have file name like "T002 20130131.zip" Now i ahve to perform below steps
1:- unzip this file "T002 20130131.zip" (Unzip T002 20130131.zip)

As per me unix take ot two diffrent nae & can't unzip this file
2:- After unzip we get file "T002 20130131"
now we have to remove the space between "T002" & "20130131" . The output should be "T00220130131"
3:- Now again zip this file "T00220130131.zip" & copy to a specfic location.

Is this possible in Linux?
 
Old 02-04-2013, 06:55 AM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Debian Sid. Arch. In the process of converting to and learning FreeBSD
Posts: 1,023
Blog Entries: 6

Rep: Reputation: 237Reputation: 237Reputation: 237
Found this snippet on the web that may help you (credit: http://stackoverflow.com/questions/2...n-file-names):

Code:
- unzip the file into a directory, say ~/tmp (replace ~/tmp with the directory you unzipped to)

- find ~/tmp -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;

- zip the files back up
Even though that expression in the find command is looking for a filename with one space, it will replace all spaces in filenames. If you don't want an underscore to replace the space, replace it with what character (or nothing at all) you want.

If you have several such files, you could write yourself a shell script to make it faster and easier.

Last edited by goumba; 02-04-2013 at 06:59 AM.
 
1 members found this post helpful.
Old 02-04-2013, 07:24 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Which distro you're using? For linux based distro you can find rename command.
Code:
~$ rename 's/ //' T002\ 20130131.zip
~$ ls -la T002*
T00220130131.zip
Tip: Use tab key after typing first 2 or 3 letters of a filename, so shell will automatically take full filename and for space characcter it will automatically add a backslash before it to avoid interpreting special characters.

And how many files you've? For more files you can create a script like:-
Code:
#!/bin/bash
echo -n "Enter filename: "; read oldname
newname=$(echo $oldname | tr -d ' ')
mv "$oldname" $newname
echo "Done for file $oldname"

Last edited by shivaa; 02-04-2013 at 07:27 AM.
 
1 members found this post helpful.
Old 02-04-2013, 07:11 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 15,388

Rep: Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199Reputation: 2199
At one time it was an option of the zip program to be able to edit the embedded file names. Not sure it that was ever in linux.
 
  


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
[SOLVED] Move file names with space to other directory with different file name with space pradeepdee6 Linux - Newbie 9 08-08-2012 10:19 AM
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 04:06 PM
Shell Script how to remove absolute paths from zip archive hi_irf Linux - Newbie 1 10-03-2009 06:59 AM
how to remove a directory name with space ? jimmyjiang Red Hat 3 03-17-2008 11:46 AM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 02:50 AM


All times are GMT -5. The time now is 04:22 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration