LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2014, 09:32 AM   #1
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Rep: Reputation: Disabled
Exclude files in gzip command


hi,

I would like to exlcude certain files which starts with AUS from a directory while gzip the files but i need it in gzip command only


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:


NZ1.gz
USA.gz
 
Old 05-01-2014, 09:47 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
So what have you tried and where are you stuck?

Have you at least read the man page and perhaps tried a google search?
 
Old 05-01-2014, 09:58 AM   #3
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Original Poster
Rep: Reputation: Disabled
i have tried something like this

Code:
gzip !(AUS*)
 
Old 05-01-2014, 10:01 AM   #4
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Rather than trying to come up with an extended glob, you can also just loop over the files and filter them with an if statement.
 
Old 05-01-2014, 10:04 AM   #5
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Original Poster
Rep: Reputation: Disabled
i don't wanted to loop becoz of performance problem becoz there are huge number of files with huge sizes
 
Old 05-01-2014, 10:06 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
U shuold ues find(1) uiltiy. And xargs(1) uttiliy.

Last edited by NevemTeve; 05-01-2014 at 10:08 AM.
 
Old 05-01-2014, 10:56 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Quote:
i don't wanted to loop becoz of performance problem becoz there are huge number of files with huge sizes
So apart from not being able to spell 'because', I am not sure I understand the relevance of this statement?

You wish to zip each file that does not match a specific pattern. How will looping through all those that do not meet the pattern be any slower than your other methods?
Also, the size of the file will only affect how quickly gzip can compress it, it will in now way affect the speed of a loop to recall its name to be included as a file that needs to be processed
 
Old 05-01-2014, 10:59 AM   #8
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Original Poster
Rep: Reputation: Disabled
Grail

i needed the solution rather than to use in loop i know loop will work but i don't wanted to use it rather to use in gzip command something like this

Code:
gzip `ls | egrep -v "AUS.*csv|AUS.*txt"`
 
Old 05-01-2014, 12:21 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
In that case you will need to follow NevemTeve's advice
 
Old 05-01-2014, 12:32 PM   #10
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Original Poster
Rep: Reputation: Disabled
Grail

can you help on the above code with invoking directly from directory rather than giving cd $directory
 
Old 05-01-2014, 12:56 PM   #11
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
What command do you have so far? Where is it broken? Post your command, and your question.
 
Old 05-01-2014, 02:41 PM   #12
mina86
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 517

Rep: Reputation: 229Reputation: 229Reputation: 229
Quote:
Originally Posted by rohit_shinez View Post
Code:
gzip `ls | egrep -v "AUS.*csv|AUS.*txt"`
Don't do that. It does not handle white space in file names correctly.

Like it has been mentioned, if you don't want to loop, the easiest option is find. And you don't even need xargs, you can do “find … -exec gzip {} +”.

Or even “find … -exec parallel gzip ::: {} +”.
 
Old 05-01-2014, 11:59 PM   #13
rohit_shinez
Member
 
Registered: Aug 2013
Posts: 40

Original Poster
Rep: Reputation: Disabled
hi achived with below one but i want to ignore any subdirectory but grep -v "^d"` is not ignoring the directory


Code:
gzip `ls | egrep -v ''AUS*[.](csv|txt)$'|grep -v "^d"`
 
Old 05-02-2014, 02:09 AM   #14
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
Why would there be a 'd' at the start of the line? Or are you just skipping those directories starting with a 'd'?
 
Old 05-02-2014, 08:05 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Mentioned "find" earlier, so please try to use it, or at least read its manual, including option "-maxdepth"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] 'find' command regex to exclude hidden files? arashi256 Linux - Newbie 3 06-28-2010 08:53 AM
Can we use exclude option in"rm" command to exclude some files/folders? yadav_rk727 Linux - Newbie 1 02-03-2010 10:14 AM
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 12:36 AM
[gzip] appears in process table after gzip command completes redmanDBA Linux - General 0 02-26-2008 06:12 AM
tar --exclude-from=files command not working cucolin@ Linux - Server 2 04-03-2007 09:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration