Exclude files in gzip command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exclude files in gzip command
# 8  
Old 05-01-2014
Thanks guys i will try these but i need to exclude file combinations how can i do that for e.g.
Code:
cd direct
AUS1.txt
AUS2.txt
NZ1.txt
AUS1.csv
AUS2.csv
USA.tx

i need to exclude file starting with AUS and ends with either .csv or .txt

output:
Code:
NZ1.gz
USA.gz

# 9  
Old 05-01-2014
Does that mean if file starts with AUS and end with .log or anything other than (.csv or .txt) you wana zip

if yes then try
Code:
gzip `ls | grep -v "AUS.*csv" | grep -v "AUS.*txt"`

This User Gave Thanks to Makarand Dodmis For This Post:
# 10  
Old 05-01-2014
it starts with AUS and ends with either .csv or .txt i need to exclude AUS.txt and AUS.csv
# 11  
Old 05-01-2014
the above command does the same.have you tried it?

Or
Code:
gzip `ls | egrep -v "AUS.*csv|AUS.*txt"`

This User Gave Thanks to Makarand Dodmis For This Post:
# 12  
Old 05-01-2014
Hi Alister,

will it be possible with your find command to exclude files starts with AUS and ends with either .csv or .txt i need to exclude AUS.txt and AUS.csv

Makarand

That really worked perfect but is there any way i can directly invoke the path using your code instead of applying using cd path. I need this to directly zip from the directory like it does
Code:
cd directory path
gzip $directory/*


Last edited by rohit_shinez; 05-01-2014 at 01:07 PM..
# 13  
Old 05-01-2014
try
Code:
find . -type f \! -name 'AUS*.*csv' -a \! -name 'AUS*.*txt' -exec gzip {} +

This User Gave Thanks to Makarand Dodmis For This Post:
# 14  
Old 05-01-2014
Quote:
Originally Posted by Makarand Dodmis
try
Code:
find . -type f \! -name 'AUS*.*csv' -a \! -name 'AUS*.*txt' -exec gzip {} +

That's not quite right. Both instances of *.* should be *..

Regards,
Alister
This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude directories in FIND command

Can you please help tweak the below command to exclude all directories with the name "logs" and "tmp" find . -type f \( ! -name "*.tar*" ! -name "*.bkp*" \) -exec /usr/xpg4/bin/grep -i "user_1" /dev/null {} + >result.out bash-3.2$ uname -a SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v... (9 Replies)
Discussion started by: mohtashims
9 Replies

2. Shell Programming and Scripting

Exclude files in ls

Hi, I need to exlucde the files which are present in exclude.txt from a directory exlcude.txt AUZ.txt AUZ.chk NZ.txt NZ.chk tried with below code but not working ls -ltr | grep -v `cat exclude.lst` (9 Replies)
Discussion started by: rohit_shinez
9 Replies

3. Shell Programming and Scripting

Need to exclude .NFSxxx files in clear old files batch script

I am new to Shell Scripting and need some help. The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Discussion started by: kimberlyg2007
2 Replies

4. UNIX for Dummies Questions & Answers

Find command to exclude files with no extension

The below 'ls' command will list down files with extensions and suppress the ones with no extension ls |grep "\\." But this dosen't work when I apply the same logic using 'find' command find . -type f |grep "\\." I need help on how this logic can be implemented using 'find' command (3 Replies)
Discussion started by: meenavin
3 Replies

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

6. Shell Programming and Scripting

Find command with exclude

I had a Shell script that removes the files that are in a directory older than the specified days. find /test/files -mtime +10 I would like to add another condition to the find command above that is to exclude any file starting with ‘CGU' Thanks (1 Reply)
Discussion started by: db2dbac
1 Replies

7. Shell Programming and Scripting

Using GZIP command

Hi All, Is it possible to redirect the o/p of gzip command to another file? I need to store the o/p in a separate file Regards, sh_kk (7 Replies)
Discussion started by: sh_kk
7 Replies

8. UNIX for Dummies Questions & Answers

list the files but exclude the files in subdirectories

If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also proj/code/test.sh proj/code/test1.c proj/code/unix... (8 Replies)
Discussion started by: shyjuezy
8 Replies

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

10. UNIX for Advanced & Expert Users

du (exclude files)

Hi, I want to get the disk usage of a directory. But I want it to ignore a particular directory within it. Lets say I want disk usage of all files/dirs within dir1 except those that are named .snapshot Does du have the option of excluding a particular directory. (1 Reply)
Discussion started by: the_learner
1 Replies
Login or Register to Ask a Question