Home > front end >  glob: Match files with multi-dotted extension but exclude some depending on sub part in extension
glob: Match files with multi-dotted extension but exclude some depending on sub part in extension

Time:05-27

I have a folder with tsx files and test tsx files structured as shown

packages
  packageName
    src
      index.tsx
      sample.tsx
      sample.test.tsx
      tests
        index.test.tsx

I have been able to so far write a glob pattern that matches the tsx files that looks like this: packages/**/*.{tsx,ts} However I would like to exclude the test files in the glob pattern, files that have .test.tsx, how would I do that

CodePudding user response:

Try

shopt -s globstar extglob
printf '%s\n' packages/**/!(*.test).@(tsx|ts)

See the extglob section in glob - Greg's Wiki.

  • Related