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 11-12-2014, 09:51 AM   #1
student1
LQ Newbie
 
Registered: Jan 2008
Posts: 27

Rep: Reputation: 0
any ZIP experts out there?


Couldn't find info on man pages...

Using Suse 13.1, I'm looking for the shell command to ZIP 3 files into Axxx.ZIP, where "A" is constant and xxx are wild cards in the name of the first file to be zipped. All filename extensions (of the files to be zipped) are .XML, but I want the extension .XML to be dropped from the new ZIP filename.

E.g.
I want to zip: A123.XML, BBBB.XML CCCC.XML
I want the name of the zipped file to be A123.ZIP

Any help would be appreciated.
Thanks.
 
Old 11-12-2014, 10:02 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Why not just tar them and zip the tar archive (or, better yet, gzip)?
 
Old 11-12-2014, 10:09 AM   #3
student1
LQ Newbie
 
Registered: Jan 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks for the quick reply. No can do tar or gzip, as the specs call for ZIP standards.
 
Old 11-12-2014, 10:27 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Maybe I'm missing the complicated part, but I don't see what zip has to do with the question. All you're trying to do is generate a filename on the fly, the actual zip command is trivial.

You need to be a bit more specific about how you want the file named. Would something like this work?
Code:
name=$(ls A*.XML | head -1)
if [[ ! -z $name ]]; then
   name=${name/.XML/.ZIP}
   zip $name *.XML
fi
If not, please explain in more detail why.

Last edited by suicidaleggroll; 11-12-2014 at 11:47 AM.
 
Old 11-12-2014, 10:27 AM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Normally, you can simply zip them into a zip archive.

The command is something like
Code:
zip zipfile_name file.xml file.xml file.xml ...
(have a look at the manual page for zip).

You could use anything you want for "zipfile_name," don't forget to put the ".zip" (it does not need to be upper case by the way) at the end of "zipfile_name".

[EDIT]
A good name would include the date, something like 20141112, in it.
[/EDIT]

If you really want to change the names of the XML files, that will take a shell program to do but there really isn't any good reason to do that (unless, of course, there's some specific need or want or whatever (users are the bane of life). You'll wind up with a big ZIP file that contains the XMLs that will be extracted into the directory you're in when you unzip.

Hope this helps some.

Last edited by tronayne; 11-12-2014 at 10:35 AM.
 
Old 11-12-2014, 11:28 AM   #6
student1
LQ Newbie
 
Registered: Jan 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks for the replies, folks.

Here's the scenario...

Specs require files A123.XML, BBBB.XML and CCCC.XML to be zipped into a .ZIP file, named A123.ZIP, where 123 are variable digits; i.e. they could be 456, 789, etc., in which case the zipped filenames would be A456.ZIP, A789.ZIP, etc. Filenames BBBB.XML and CCCC.XML are constants (fixed)

I tried the script:

name=$(ls A*.XML | head -1)
if [[ ! -z $name ]]; then
name=${name/.XML/.ZIP}
zip $name *.XML
endif

Not sure what I'm doing wrong, but got a syntax error, "line 6: syntax error: unexpected end of file"

The command Code: "zip zipfile_name file.xml file.xml file.xml ..." doesn't cut it because the the digits that make up "zipfile_name" vary.

(Upcase characters are part of the specs).)
 
Old 11-12-2014, 11:47 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Sorry, that should be "fi", not "endif".
 
1 members found this post helpful.
Old 11-12-2014, 11:50 AM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by student1 View Post
Specs require files A123.XML, BBBB.XML and CCCC.XML to be zipped into a .ZIP file, named A123.ZIP, where 123 are variable digits; i.e. they could be 456, 789, etc., in which case the zipped filenames would be A456.ZIP, A789.ZIP, etc. Filenames BBBB.XML and CCCC.XML are constants (fixed)
Still not enough information to write a proper, robust script. Are these files all in the same directory? Which directory? Is the script there too? Where is the user? Should they be able to run it from anywhere or do they have to be inside that directory? Are there any other files in the directory? Do any of them end in XML? Do any of them start with A? Could there be more than one A*.XML file? Could there be no A*.XML file? In either case, what do you want the script to do? What if BBBB.XML or CCCC.XML isn't there? What if there is also a DDDD.XML? What do you want the script to do?

This is sounding more and more like a homework problem to me...

Last edited by suicidaleggroll; 11-12-2014 at 11:51 AM.
 
1 members found this post helpful.
Old 11-12-2014, 12:08 PM   #9
student1
LQ Newbie
 
Registered: Jan 2008
Posts: 27

Original Poster
Rep: Reputation: 0
Thanks, suicidaleggroll. Your revised script worked just fine. I'm OK with all the other stuff - file locations, directory structuring, etc.

FYI, the project is part of a medicare billing routine transition to Linux I took on to help pay the groceries. The zipped files are to be uploaded to medicare's server.

(Looks like tomorrow the kids can eat. Thanks again.)
 
  


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
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 07:06 PM
drivers for iomega zip 250 zip driveH tony044 Linux - Newbie 5 09-14-2010 06:19 AM
PHP ZIP MYSQL - open zip without writing it to disk benjalien Programming 2 01-15-2010 05:14 AM
Linux: By Experts - For Experts Cinematography General 10 05-12-2005 02:14 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 01:43 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