The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unzip files in a different folder agarwalniru UNIX for Dummies Questions & Answers 2 03-25-2008 12:36 PM
How redirect output(error and normal) to 2 different files balareddy Shell Programming and Scripting 2 09-12-2007 10:05 AM
Copy files from CD and Unzip AJD UNIX for Dummies Questions & Answers 1 04-15-2004 04:43 AM
Normal user access to files/folders gdboling UNIX for Dummies Questions & Answers 1 12-04-2002 07:46 PM
unzip .tgz files Prafulla UNIX for Dummies Questions & Answers 5 02-09-2002 07:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-30-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
unzip particular gzip files among the normal data files

Hello experts,

I run Solaris 9. I have a below script which is used for gunzip the thousand files from a directory.
----
#!/usr/bin/sh
cd /home/thousands/gzipfiles/
for i in `ls -1`
do
gunzip -c $i > /path/to/file/$i
done
----
In my SAME directory there thousand of GZIP file and also thousands of data files(already been unzipped) with same name unixtt*

bash-2.05$ file unixtt01674
unixtt01674: data

bash-2.05$ file unixtt01677
unixtt01677: gzip compressed data - deflate method


Is it possible I can just unzip only GZIP unixtt* files leaving the data unixtt* files.?? What should i need to add in the script ??

//purple
Reply With Quote
Forum Sponsor
  #2  
Old 11-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by thepurple View Post
Is it possible I can just unzip only GZIP unixtt* files leaving the data unixtt* files.?? What should i need to add in the script ??
Firstly sort out your naming conventions so files that are compressed do have an extension indicating the compression method, eg .Z, .gz etc.

If "file" can tell you what is a gzipped file, then use that to tell you in the script.
Reply With Quote
  #3  
Old 11-30-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
purple

my GZIP Files have no extension. its just appear without extension. So, litterally just to see the files it is not possible which one is data and which one is Gzip.

Quote:
Originally Posted by porter View Post
If "file" can tell you what is a gzipped file, then use that to tell you in the script.
Please provide me the coding lines how to define "file" in script....
Reply With Quote
  #4  
Old 11-30-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by thepurple View Post
So, litterally just to see the files it is not possible which one is data and which one is Gzip.
I suggest you review that strategy.

Quote:
Originally Posted by thepurple View Post
Please provide me the coding lines how to define "file" in script....
something like

Code:
file $somefile | grep "gzip compressed data"
if test "$?" = "0"
then
    echo $somefile is gzipped
fi
Reply With Quote
  #5  
Old 11-30-2007
Registered User
 

Join Date: Oct 2007
Posts: 68
hi guys,

Below is worked for me. Thanks buddies for the hints--
#!/usr/bin/sh
cd /thousand/files/
for i in `ls`
do
l=`file $i|grep gzip|wc -l`

if [ $l -ne 0 ]; then
gunzip -c $i > /path/to/file/$i
fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




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


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

Content Relevant URLs by vBSEO 3.2.0