LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 04: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, 05:55 AM   #2
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
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 05:59 AM.
 
1 members found this post helpful.
Old 02-04-2013, 06: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 06:27 AM.
 
1 members found this post helpful.
Old 02-04-2013, 06:11 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
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



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 09: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 03:06 PM
Shell Script how to remove absolute paths from zip archive hi_irf Linux - Newbie 1 10-03-2009 05:59 AM
how to remove a directory name with space ? jimmyjiang Red Hat 3 03-17-2008 10:46 AM
create a self-extracting zip file with zip on solaris? samsolaris Solaris / OpenSolaris 3 10-15-2004 01:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:20 PM.

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