Monday, July 25, 2022

[SOLVED] glob: Match files with multi-dotted extension but exclude some depending on sub part in extension

Issue

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


Solution

Try

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

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



Answered By - pjh
Answer Checked By - David Marino (WPSolving Volunteer)