Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Quick script

Posted on 2006-07-18
5
Medium Priority
?
185 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 1800 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 200 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 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