unzip particular gzip files among the normal data files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unzip particular gzip files among the normal data files
# 1  
Old 11-30-2007
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  
Old 11-30-2007
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  
Old 11-30-2007
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  
Old 11-30-2007
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  
Old 11-30-2007
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 to Ask a Question

Previous Thread | Next Thread

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 selected files

Hi, In file zip folder i have many files but i want to extract onlu .LOG file from the zip. How can i achive this Rajesh (3 Replies)
Discussion started by: guddu_12
3 Replies

6. Shell Programming and Scripting

Unzip .tla files

Hi , I have a file which is with extension .tla. I have no idea what file it is so can anybody let me know what it is?. Regards, Chetan.C (1 Reply)
Discussion started by: chetan.c
1 Replies

7. UNIX for Advanced & Expert Users

how to unzip files in different directories

Hi there: Is there any fest way to upzip files that distributed in several directories and their sub-directory instead of unzipping them directory by directory?? Thanks a lot!!! (1 Reply)
Discussion started by: cls3415
1 Replies

8. 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

9. 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

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
Login or Register to Ask a Question