Solved

Quick script

Posted on 2006-07-18
5
179 Views
Last Modified: 2010-04-22
Hi,

I need to write a script that will take all the files ending in .sal in the current directory (say /tmp/) and create individual zip files i.e :

test.sal ->  test.zip

There could be any amount of .sal files...

I'd rather do this with a bash script but can use Perl in a pinch....

Thanks in advance!
0
Comment
Question by:petepalmer
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17128516
Hi petepalmer,

find /tmp -type f -name "*.sal" | while read fname
do
       gzip -c $fname > $fname.gz
done

Cheers!
sunnycoder
0
 
LVL 1

Author Comment

by:petepalmer
ID: 17128530
Very close.... but.... :)

The final name needs to be (in the case of test.sal) test.zip not test.sal.zip :)

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 450 total points
ID: 17128538
Hi petepalmer,

find /tmp -type f -name "*.sal" | while read fname
do
       fname2=`echo "$fname" | sed 's/\.sal//'`
       gzip -c $fname > $fname2.gz
done

Cheers!
sunnycoder
0
 
LVL 43

Assisted Solution

by:ravenpl
ravenpl earned 50 total points
ID: 17128586
find /tmp -type f -name "*.sal" | while read fname
do
       fname2=`echo -n "$fname" | sed 's/\.sal//'`
       zip "/tmp/$fname2.zip" "$fname"
done
0
 
LVL 1

Author Comment

by:petepalmer
ID: 17128606
450 to sunny as the answer was spot on, 50 for raven for the assist :)

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question