Home > Software engineering >  Regex alternative to find files
Regex alternative to find files

Time:01-01

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:

 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

CodePudding user response:

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.

  •  Tags:  
  • bash
  • Related