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 alternative to find files

When I attempt the regex alternative to find files in my downloads, especially, for this instance to get .csv extensions, I get nothing returned.

I know I can get these files with:

find . -name '*.csv'

However, none of my regex alternatives with find work, for example:

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 . -regextype sed -regex '.csv$'

Returns nothing even though it’s a working regular expression. Neither does the following:

find . -regextype sed -regex '(?<=\/)(.*?).csv$'

When my files look like:

./audienceBuild1.py
./audiences.json
./authorize
./bingoXandr.csv
./Book1.xlsx
./Book10.xlsx
./book2.pdf
./Campaigns (1).csv
./Campaigns.csv
./catalogue.csv
./coords.jl

>Solution :

You can do the following

find . -regextype sed -regex '.*\.csv'

What does this mean?

  • .* refers to the longest string containing any element in this pattern;
  • \.csv refers to the literal string .csv

Note how the dot needs to be escaped, otherwise it is seen as any character.

I believe this should work.

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