4

This question already has an answer here:

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.

marked as duplicate by don_crissti, Community Nov 28 '15 at 11:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5
find . -maxdepth 1 -iname '*.txt' -not -name 'DISCARD.txt' -exec cat {} +>catKEPT
2

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.

  • I tried it, but command got stuck (no output) – dovah Nov 28 '15 at 11:15
  • Are you sure you have bash ? Try echo $SHELL to know what shell you are using. – perror Nov 28 '15 at 11:16
  • OP wants to cat only .txt files so you'll have to use the glob like this: cat -- !(DISCARD).txt – don_crissti Nov 28 '15 at 11:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.