I'm looking for something to concatenate all files with given extension within a directory, except one. Like:
cat *.txt !(DISCARD.txt) > catKEPT
This should concatenate all *.txt files in directory, except DISCARD.txt.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI'm looking for something to concatenate all files with given extension within a directory, except one. Like:
cat *.txt !(DISCARD.txt) > catKEPT
This should concatenate all *.txt files in directory, except DISCARD.txt.
If you are using bash
(most of the time this is the case), you may use the extglob
shell option that will extend your shell with a more powerful pattern matching syntax.
You can turn it on with shopt -s extglob
, and turn it off with shopt -u extglob
.
In your example, you would simply do:
$ shopt -s extglob
$ cat -- !(DISCARD).txt > catKEPT
You can find more about this command in this StackOverflow answer.
bash
? Try echo $SHELL
to know what shell you are using.
.txt
files so you'll have to use the glob like this: cat -- !(DISCARD).txt
Nov 28, 2015 at 11:32