I am just starting learning regex and want to use it instead of others everywhere for practice.
I encounter such a situation when tried to find files with extensions sh or md
$ find . regex ".*\.(sh|md)$"
.
./bogus.py
./cofollow.py
./data8.txt
./example.sh
./longest_word_2.sh
./posit_param.sh
./cobroadcast2.py
Unfortunately it output /bogus.py
,
I notice the BRE rules and tried escape ()
$ find . -regex ".*\.\(sh|md\)$"
#get nothing return
After series of search, I got -regextype solution Regular Expressions - Finding Files
$ find . -regextype posix-extended -iregex ".*\.(sh|md)$"
./example.sh
./longest_word_2.sh
./posit_param.sh
$ find . -regextype egrep -iregex ".*\.(sh|md)$"
./example.sh
./longest_word_2.sh
./posit_param.sh
./table_regex_bat.md
Additionally, a nice modular solution
$ find -type f | egrep ".*\.(sh|md)$"
./example.sh
./longest_word_2.sh
./posit_param.sh
./table_regex_bat.md
However, there is a shortcut in BSD to accomplish such a task
with a -E
predicate.
$ /usr/bin/find -E . -regex ".*\.(sh|md)$"
./example.sh
./longest_word_2.sh
./posit_param.sh
I am determined to exclusively take the GNU tool in order to make my codes and skills portable.
So I am starting to alias 'find -regextype egrep`,
Unfortunately find obtain the $1 as path.
How could I solve them problem in a handy way?
printf
allows printing one file per line. – Stéphane Chazelas Nov 02 '18 at 11:00