• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Quick script

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
petepalmer
Asked:
petepalmer
  • 2
  • 2
2 Solutions
 
sunnycoderCommented:
Hi petepalmer,

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

Cheers!
sunnycoder
0
 
petepalmerAuthor Commented:
Very close.... but.... :)

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

0
 
sunnycoderCommented:
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
 
ravenplCommented:
find /tmp -type f -name "*.sal" | while read fname
do
       fname2=`echo -n "$fname" | sed 's/\.sal//'`
       zip "/tmp/$fname2.zip" "$fname"
done
0
 
petepalmerAuthor Commented:
450 to sunny as the answer was spot on, 50 for raven for the assist :)

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now