Solved

Quick script

Posted on 2006-07-18
5
177 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
450 to sunny as the answer was spot on, 50 for raven for the assist :)

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Software required to mount Linux LVM Volume 6 388
linux $PWD 2 533
Openwrt vnstat 9 110
monitor and log every file access on redhat/linux 4 97
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 demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now