Your regular expression is underspecified. The goal is to eliminate files beginning with AUS, but you are eliminating anything that contains AUS. A leading anchor is required.
Using find is a much better solution; it is just as efficient (if not more so) and is safe against exceeding ARG_MAX with a massive argument list:
find . -type f \! -name 'AUS*' -exec gzip {} +
Regards,
Alister
---------- Post updated at 09:39 AM ---------- Previous update was at 09:34 AM ----------
If the shell supports it, and if you're willing to risk the implosion, you can use:
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
It's beginning to seem that you are unwilling to help yourself. We are into double digit post count and there's no indication that you've actually tried any off the suggestions.
Why don't you just go ahead and run some tests? If there are problems or shortcomings, try to fix them yourself. If you succeed, report back with your changes so that others can benefit. If you fail, then post the exact errors seen so that we have more information to work with.
when i am using the test directory getting the below error
gzip `ls test| egrep -v "AUS.*csv|AUS.*txt"`
gzip: can't stat: NZ.csv (NZ.csv): No such file or directory
gzip: can't stat: NZ.txt (NZ.txt): No such file or directory
Going back to your first post to this thread, you said you have a directory named test in the current directory containing the four files:
direct:
AUS1.tx
AUS2.txt
and
NZ1.txt
Now you are saying that you want to invoke the command:
gzip direct: AUS1.tx NZ1.txt
in a directory where none of these files exist.
So, you can choose to use a cd command to get into the directory where those files exist, or you can choose a completely different way to get the list of filenames to be given to gzip .
Why are you so opposed to using the cd command?
What does the following command do:
cd test;gzip `ls | egrep -v '^AUS.*[.](csv|txt)$'
that is different from what you have said you want?