0

Using the command bellow:

find ./stylesheets/sass/ -maxdepth 1 -type f -regextype posix-egrep -regex '[^_].+\.scss'

I get this:

./stylesheets/sass/_hero.scss
./stylesheets/sass/_article-type.scss
./stylesheets/sass/app.scss
./stylesheets/sass/_footer.scss
./stylesheets/sass/_grid-items.scss

and I wanted just:

./stylesheets/sass/app.scss

so my negation [^_] of underscore, does not work beacuse it tries to match at the very beginning of a path, I suppose, and not the filename itself.

How to solve this, keeping it flexible enough for any depth of dirs before the actual filename?

2
  • No, it's matching 1 character that's not a _, followed by more than one character that can be anything, followed by the extension. Commented May 25, 2014 at 0:05
  • @Wooble I know what my regex is. That is not my question. Commented May 25, 2014 at 0:10

1 Answer 1

4

Just do it with -name:

find ... -name '[^_]*.scss'

Alternatively, if you insist on using -regex, make sure your not-underscore is only in the last component of the pathname:

find ... -regex '.*/[^/_][^/]*\.scss$'
Sign up to request clarification or add additional context in comments.

2 Comments

great, could you tell me which one of these is more portable?
The first one is POSIX, the second is not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.