gzip files with extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting gzip files with extension
# 1  
Old 07-22-2010
gzip files with extension

Hi,

I have 1000 of files in a folder with the file extension as .csv
In this some of the files are already zipped and its looks like filename.csv.gz

Now i need to zip all the files in the folder to free some disk space. When i give gzip *.csv

It prompts me to overwrite filename.csv.gz files which are already zipped.

Is there any way to exclude the already zipped files and zip only the files with .csv extension which are not zipped.

Thanks in Advance.
# 2  
Old 07-22-2010
Code:
ls *.csv | egrep -v $(ls *.gz | sed "s/.gz/.csv/" | tr '\n' '|' |sed "s/|$//")

Verify the output of above command and then use that in gzip command
# 3  
Old 07-22-2010
Hi.

Another option:

Code:
false | gzip *.csv

# 4  
Old 07-22-2010
try this it will not prompt for anything---

Code:
ls -1 *.csv | gzip * 2>/dev/null


Last edited by Scott; 07-22-2010 at 02:40 PM.. Reason: Code tags
# 5  
Old 07-22-2010
Quote:
Originally Posted by sachinkl
try this it will not prompt for anything---

ls -1 *.csv | gzip * 2>/dev/null
Are you sure?

What would gzip * expand to?

Code:
$ echo blah | tee xxxxx.csv > yyyyy
$ ll
total 16
drwxr-xr-x   4 scott  staff   136 22 Jul 19:43 .
drwxr-xr-x  43 scott  staff  1462 22 Jul 19:41 ..
-rw-r--r--   1 scott  staff     5 22 Jul 19:43 xxxxx.csv
-rw-r--r--   1 scott  staff     5 22 Jul 19:43 yyyyy
$ ls *.csv | gzip *
$ ll
total 16
drwxr-xr-x   4 scott  staff   136 22 Jul 19:43 .
drwxr-xr-x  43 scott  staff  1462 22 Jul 19:41 ..
-rw-r--r--   1 scott  staff    35 22 Jul 19:43 xxxxx.csv.gz
-rw-r--r--   1 scott  staff    31 22 Jul 19:43 yyyyy.gz



---------- Post updated at 07:54 PM ---------- Previous update was at 07:39 PM ----------

(the "Are you sure" question was related to whether it worked, not whether it would prompt you for anything. But it neither works nor prompts you, so you were half right Smilie)
# 6  
Old 07-22-2010
1. below command can help you directly. It will only compress the .csv file.

Code:
gzip *.csv

2. Even there are gzip files already, gzip command will not touch them:

Code:
$ ls |grep csv
file1.csv.gz
file2.csv.gz
xxx.csv

$ gzip *.csv

$ ls *.csv
file1.csv.gz
file2.csv.gz
xxx.csv.gz

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

Python - glob () - How to grep same files with different extension files

Hi I Have a directory and i have some files below abc.txt abc.gif gtee.txt ghod.pid umni.log unmi.tar How can use glob function to grep abc files , i have created a variable "text" and i assigned value as "abc", please suggest me how can we use glob.glob( ) to get the output as below... (2 Replies)
Discussion started by: kumar85shiv
2 Replies

3. Shell Programming and Scripting

tar and gzip files

Hi Guys, I am using RHEL5 and Solaris 9 & 10. I want to tar and gzip my files then remove them after a successful tar command... Lets say I have files with extension .arc then I want to tar and gzip these files. After successful tar command I want to remove all these files (i.e .arc). ... (3 Replies)
Discussion started by: Phuti
3 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 the files with particular extension

Is there any way to compress only the files with .xml extension within a folder which in turn has many sub folders? gzip -r9 path/name/*.xml is not working This compression is done in the Windows server using Batch script. (2 Replies)
Discussion started by: Codesearcher
2 Replies

6. Shell Programming and Scripting

Gzip files as they are created

Hello. I have a scripting query that I am stumped on which I hope you can help with. Basically, I have a ksh script that calls a process to create n number of binary files. These files have a maximum size of 1Gb. The process can write n number of files at once (parallel operation) based on the... (4 Replies)
Discussion started by: eisenhorn
4 Replies

7. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: thepurple
4 Replies

8. UNIX for Dummies Questions & Answers

gzip all the files in a directory

Hi, There are multiple files in a directory with different names.How can they be gzipped such that the timestamp of the files is not changed. (2 Replies)
Discussion started by: er_ashu
2 Replies

9. UNIX for Dummies Questions & Answers

Need to gzip LARGE files

The windows version of gzip supports pretty much unlimited file sizes while the one we have in solaris only goes up to a set size, one or two gigs I think. Is there a new version of gzip I can put on our systems that supports massive file sizes? (2 Replies)
Discussion started by: LordJezo
2 Replies

10. UNIX for Dummies Questions & Answers

gzip, multiple files

Hello Everyone, Here is what I am trying to do. I have four text files, I want to gzip them under unix and mail the zipped file via outlook. I am able to do this easily enough, but using winzip or pkunzip to unzip the file, there is only one file. (In essence, all four files were... (2 Replies)
Discussion started by: smbodnar
2 Replies
Login or Register to Ask a Question