The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 03:36 PM
How redirect output(error and normal) to 2 different files balareddy Shell Programming and Scripting 2 09-12-2007 01:05 PM
Copy files from CD and Unzip AJD UNIX for Dummies Questions & Answers 1 04-15-2004 07:43 AM
Normal user access to files/folders gdboling UNIX for Dummies Questions & Answers 1 12-04-2002 10:46 PM
unzip .tgz files Prafulla UNIX for Dummies Questions & Answers 5 02-09-2002 10:38 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2007
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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
  #2 (permalink)  
Old 11-30-2007
porter porter is offline Forum Advisor  
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.
  #3 (permalink)  
Old 11-30-2007
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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....
  #4 (permalink)  
Old 11-30-2007
porter porter is offline Forum Advisor  
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
  #5 (permalink)  
Old 11-30-2007
thepurple thepurple is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 134
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0