script for Gzip thousands of file


 
Thread Tools Search this Thread
Operating Systems Solaris script for Gzip thousands of file
# 1  
Old 12-28-2007
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.
# 2  
Old 12-28-2007
Isn't that quite straight forward ( or I didn't read that completely ? )

Code:
ls file* | while read file
do
gzip "$file"
done

# 3  
Old 12-28-2007
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.
# 4  
Old 12-28-2007
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

# 5  
Old 12-28-2007
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 07:55 PM.. Reason: code tags
# 6  
Old 12-30-2007
purple

Quote:
Originally Posted by frank_rizzo

Code:
   if ! gzip -t ${f} 2>/dev/null

what is the the meaning of the abve code? mainly 2> /dev/null
# 7  
Old 12-30-2007
purple

Quote:
Originally Posted by rubionis
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}'`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script not able to zip the file using gzip

Hi all, I am calling Temp.sh and it is has simple line $gpath=`which gzip` $gpath $FilePath/My_temp.log if I run this script, logging to server then its works fine. But when I send this script over the SSH it does not work at it. gzip is command is not execute. I am using gzip 1.6... (2 Replies)
Discussion started by: girijajoshi
2 Replies

2. Shell Programming and Scripting

Help/How-to - simple UNIX script / gzip (beginner)

Hey all, I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this. I need to create a UNIX script that will: - scan a small number of folders and subfolders (see a similar file tree in the attachment) - - for each final folder (each of... (8 Replies)
Discussion started by: McNulty
8 Replies

3. Shell Programming and Scripting

help with a script to gzip/move files

Hi Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory. Your help will be appreciated. (4 Replies)
Discussion started by: fretagi
4 Replies

4. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

5. Shell Programming and Scripting

gzip and encrypted in a shl script

After I move the file to a directory, I need to gzip and encrypted. I never do this in a shl script, I do it from the command line and it works.. cd /home/nelnet spinel:/home/nelnet$ gpg -e 2010_11_07_05_11_xxxxxx_bills.dat.gz `/home/nelnet/.gnupg/gpg.conf' `/home/nelnet/.gnupg/gpg.conf'... (3 Replies)
Discussion started by: rechever
3 Replies

6. Shell Programming and Scripting

script with dates to gzip and remove

Good morning all! I am new to programming and trying to learn; please be patient. I am wanting to write a script that takes the current date and gzip 5 days or older, then remove 10 days or older. This is the directory I want to work in; this is what it looks like ... (2 Replies)
Discussion started by: bigben1220
2 Replies

7. Solaris

gzip a file and append creation date stamp to file

I want to gzip a file and append the creation date to the end of the file. How can I accomplish this task. Basically they are log files which need a creation date stamp appended to make sure they do not overwrite other log files. -jack (3 Replies)
Discussion started by: jacktravine
3 Replies

8. UNIX for Dummies Questions & Answers

How to truncate thousands of file names

Folder of e-mails in maildir format had been corrupted. Typical file name is 1246281161.6777.m21JH:2,S . The " :2,S prevents " copying to another device. How can I simply remove the last four characters? (2 Replies)
Discussion started by: steve900
2 Replies

9. UNIX for Dummies Questions & Answers

How do I send a file as an attachment (gzip file) on a Unix system

Hi, How do I send a file as an attachment (gzip file) on a Unix system ? Using sendmail. Please help me. :confused: (3 Replies)
Discussion started by: lacca
3 Replies

10. Shell Programming and Scripting

gzip in shell script called by cron

I'm puzzled by this one. I hope you can explain it to me. I have a ksh shell script that gzips a file among other things. This works perfectly fine when the script is manually run through a shell. However, when the same script is run through cron, it does everything correctly, but it will... (2 Replies)
Discussion started by: hbau419
2 Replies
Login or Register to Ask a Question

Featured Tech Videos