Solved

Quick script

Posted on 2006-07-18
5
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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