Finding Files with Capital Letters Only in Shell Script

  • Thread starter Thread starter Bimpo
  • Start date Start date
  • Tags Tags
    files Shell
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
Bimpo
Messages
9
Reaction score
0

Homework Statement



I have a really basic task in which I have to make a shell script, pipe ls to grep and
only output files that has capitals in it, meaning no lower case, no symbols, no numbers, etc.

I've been searching all over google and my notes but I've been doing this over an hour and still can't figure it out

Homework Equations



None.

The Attempt at a Solution



I tried ls | grep [A-Z][^a-z0-9]
but it prints words with symbol such as "_" eg: "DAFA_FDSA".
 
Physics news on Phys.org
Welcome to PF, Bimpo! :smile:

Apparently you need to learn a little more about regular expressions.
Right now you're matching files that have at least one capital in it, followed by 1 symbol that is not a lowercase letter of digit.

You will need to match the beginning and end of the filename with ^ resp. $, and you will have to specify that they all have to be uppercase letters, using * to indicate zero or more repetitions.