unzip particular gzip files among the normal data files


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unzip particular gzip files among the normal data files
# 1  
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  
Quote:
Originally Posted by thepurple
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  
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
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  
Quote:
Originally Posted by thepurple
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
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  
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
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #546
Difficulty: Medium
In computer science, an operator takes the values of its operands and combines them in some way to produce a new value.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

2. Shell Programming and Scripting

Script to unzip files and Rename the Output-files

Hi all, I have a many folders with zipped files in them. The zipped files are txt files from different folders. The txt files have the same names. If i try to find . -type f -name "*.zip" -exec cp -R {} /myhome/ZIP \; it fails since the ZIP files from different folders have the same names and... (2 Replies)
Discussion started by: pmkenya
2 Replies

3. AIX

Moving Hidden files to normal files

I have a bunch of hidden files in a directory in AIX. I would like to move these hidden files as regular files to another directory. Say i have the following files in directory /x .test~1234~567 .report~5678~123 .find~9876~576 i would like to move them to directory /y as test~1234~567... (10 Replies)
Discussion started by: umesh.narain
10 Replies

4. UNIX for Dummies Questions & Answers

Unzip the Files

I have a list of zip files and regular files in a folder /home/data/ Example: PMExtra_A123_ABC_121001020000.zip PMExtra_B596_GRT_121001020000.zip PMExtra_C156_SFD_121001020000.zip PMExtra_S243_KDF_121001020000.xml PMExtra_L234_IDF_121001020000.xml I have to unzip all the .zip... (8 Replies)
Discussion started by: eskay
8 Replies

5. Shell Programming and Scripting

Unzip files without overwriting

Hi, 1)I have two zip files a.zip and b.zip. a.zip contains the files a.txt,b.txt and c.txt b.zip contains the files a.txt,b.txt,d.txt,e.txt Though some of the filenames in a.zip and b.zip are same, the size is different,i.e., the files are completely different even though their name is same.... (1 Reply)
Discussion started by: donisback
1 Replies

6. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

7. UNIX for Dummies Questions & Answers

unzip files in a different folder

hi , I am using this command to unzip files from a source unzip -o $source_dir -d $dest_dir butthe problem is that this command creates a new folder at the destination and unzips all the files in that folder. I dont want that extra folder. e.g source_dir= abc/myname.zip... (2 Replies)
Discussion started by: agarwalniru
2 Replies

8. Shell Programming and Scripting

How redirect output(error and normal) to 2 different files

Hello, I have a java program which i am calling in shell script. I wanted to redirect output to 2 differetn files. Output should have both 1 & 2 (normal and error) in both file. pls help (2 Replies)
Discussion started by: balareddy
2 Replies

9. UNIX for Dummies Questions & Answers

Copy files from CD and Unzip

Hi, I've just installed solaris 9 onto a SPARC box and am connecting to the machine via a console cable using hyper terminal. Unfortunately i have not got a monitor so i'm having to do all my config using the command line (which i'm no good at) I'm trying to copy a patch cluster (ZIP) file... (1 Reply)
Discussion started by: AJD
1 Replies

10. UNIX for Dummies Questions & Answers

Normal user access to files/folders

I was wondering if there is a way to give my regular user on Linux right to the /var/www/html folder and files therin without going into SU mode every time. Thanks. Gregg (1 Reply)
Discussion started by: gdboling
1 Replies