Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

regex to exclude lowercase only strings, but save strings which contain capital

Look to those regex

find /tmp/MG/virt-manager-5.0.0/ -maxdepth 1 -type f |grep -v  [^a-z]+\.[^a-z]+
/tmp/MG/virt-manager-5.0.0/.mailmap
/tmp/MG/virt-manager-5.0.0/virt-manager
/tmp/MG/virt-manager-5.0.0/DESIGN.md
/tmp/MG/virt-manager-5.0.0/meson.build
/tmp/MG/virt-manager-5.0.0/NEWS.md
/tmp/MG/virt-manager-5.0.0/.gitignore
/tmp/MG/virt-manager-5.0.0/README.md
/tmp/MG/virt-manager-5.0.0/.pylintrc
/tmp/MG/virt-manager-5.0.0/.coveragerc
/tmp/MG/virt-manager-5.0.0/virt-install
/tmp/MG/virt-manager-5.0.0/.packit.yaml
/tmp/MG/virt-manager-5.0.0/COPYING
/tmp/MG/virt-manager-5.0.0/virt-xml
/tmp/MG/virt-manager-5.0.0/virt-manager.spec.in
/tmp/MG/virt-manager-5.0.0/INSTALL.md
/tmp/MG/virt-manager-5.0.0/meson_options.txt
/tmp/MG/virt-manager-5.0.0/virt-manager.spec
/tmp/MG/virt-manager-5.0.0/virt-clone
/tmp/MG/virt-manager-5.0.0/CONTRIBUTING.md
/tmp/MG/virt-manager-5.0.0/setup.cfg

I want to get strings which contain CAPITAL letters, including .md .txt but only if words contain at least one capital letter, to explain better

CONTRIBUTING.MD OK
CONTRIBUTING.txt OK
CONTRIBUTING.TXT OK
Contributing.txt OK (has one capital letter)
hello.TXT OK (contain some capital letters)
contributing.txt NO (only lowercase)

I want to obtain this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  find /tmp/MG/virt-manager-5.0.0/ -maxdepth 1 -type f |grep -v REGEXWORKS

    /tmp/MG/virt-manager-5.0.0/DESIGN.md
    /tmp/MG/virt-manager-5.0.0/NEWS.md
    /tmp/MG/virt-manager-5.0.0/README.md
    /tmp/MG/virt-manager-5.0.0/COPYING
    /tmp/MG/virt-manager-5.0.0/INSTALL.md
    /tmp/MG/virt-manager-5.0.0/CONTRIBUTING.md

how to do? Thanks

>Solution :

Simply like this:

$ find . -type f -name '*[A-Z]*' 
./virt-manager-5.0.0/COPYING
./virt-manager-5.0.0/NEWS.md
./virt-manager-5.0.0/INSTALL.md
./virt-manager-5.0.0/README.md
./virt-manager-5.0.0/CONTRIBUTING.md
./virt-manager-5.0.0/DESIGN.md

The -type f is to match only files

If you prefer a regex:

find . -type f  | grep '[[:upper:]]'

that can be better written as:

find . -type f -regextype 'egrep' -regex '.*[[:upper:]].*'

because the grep version will match on directories if they contains UPPER CASE, and this is not what you want

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading