The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
thousands separator ynixon Shell Programming and Scripting 11 04-13-2008 07:43 AM
Multiple (thousands) of Cron Instances sysera UNIX for Advanced & Expert Users 10 01-17-2006 05:49 AM
How do I send a file as an attachment (gzip file) on a Unix system lacca UNIX for Dummies Questions & Answers 3 07-03-2002 10:04 AM
gzip in shell script called by cron hbau419 Shell Programming and Scripting 2 02-05-2002 03:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-28-2007
Registered User
 

Join Date: Oct 2007
Posts: 50
Stumble this Post!
script for Gzip thousands of file

Hi experts,

I have thousands of file (data file and Gziped file) in same directory like below--

bash-2.05$ pwd
/home/mmc

bash-2.05$ file PP023149200709270546
TT023149200709270546: gzip compressed data - deflate method

bash-2.05$ file PP027443200711242320
TT027443200711242320: data

i have script which i used before to UNZIP the Gzip files and send it to another directory Among those files Gzip & data files.
Code:
#!/usr/bin/sh
cd /home/mmc/
for i in `ls PP02*`
do
l=`file $i|grep gzip|wc -l`

if [ $l -ne 0 ]; then
gunzip -c $i > /home/mmc/zip/$i
fi
done
Now i need to reverse way. i.e. GZIP the files among those.

Please help me to write the script.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-28-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
Isn't that quite straight forward ( or I didn't read that completely ? )

Code:
ls file* | while read file
do
gzip "$file"
done
Reply With Quote
  #3 (permalink)  
Old 12-28-2007
Registered User
 

Join Date: Oct 2007
Posts: 50
Stumble this Post!
no it is not straight forward, becuase in the same directory there are thousands of GZIP and thousands of Data file. While Gziping i need to only GZIP the data files only.
Reply With Quote
  #4 (permalink)  
Old 12-28-2007
Registered User
 

Join Date: Dec 2007
Posts: 255
Stumble this Post!
Try this

Code:
ls prefix* | while read f
do
   if ! gzip -t ${f} 2>/dev/null
   then
      gzip ${f} 
      # you might want to rename ${f}.gz to ${f} here
   fi
done
Reply With Quote
  #5 (permalink)  
Old 12-28-2007
Registered User
 

Join Date: Aug 2007
Posts: 9
Stumble this Post!
Hi

The previous time you posted about the similar script I had a hard time understanding your request, so please include all the necessary details in your request. For example what are you going to do with the created files, move them, rename them,...? More details help us to help you.

The below script tested on a Linux machine.


Code:
for i in `ls | xargs file | awk -F: '! /gzip/{print $1}'`
 do
    gzip $i
 done

#Now the files have the extension gz. If you need to move the files in a different directory afterwards:

for i in `ls | grep gz`
 do
   mv $i /home/other_dir/
 done



Glad to hear you got the script working the first time.

Last edited by rubionis; 04-15-2008 at 02:55 PM. Reason: code tags
Reply With Quote
  #6 (permalink)  
Old 12-30-2007
Registered User
 

Join Date: Oct 2007
Posts: 50
Stumble this Post!
purple

Quote:
Originally Posted by frank_rizzo View Post

Code:
   if ! gzip -t ${f} 2>/dev/null
what is the the meaning of the abve code? mainly 2> /dev/null
Reply With Quote
  #7 (permalink)  
Old 12-30-2007
Registered User
 

Join Date: Oct 2007
Posts: 50
Stumble this Post!
purple

Quote:
Originally Posted by rubionis View Post
Hi

...so please include all the necessary details in your request. ...

The below script tested on a Linux machine.

for i in `ls | xargs file | awk -F: '! /gzip/{print $1}'`
do
gzip $i
done

#Now the files have the extension gz. If you need to move the files in a different directory afterwards:

for i in `ls | grep gz`
do
mv $i /home/other_dir/
done
Many Thanks rubionis. Below things i wanna do-

-- I will Gzip the data file in the original name of the file.
-- I do not want .gz extensions with a Gziped file.
-- After Gzip i will send those files in different directory.

Please also tell me the explanation of ur below code-
Code:
for i in `ls | xargs file | awk -F: '! /gzip/{print $1}'`
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0