Regular Expression on Directory Contents

This should be an easy question for you gurus. :slight_smile:

How can I create a regular expression to match all files in the current directory that have only one period in their file name, and also not contain the string "abc" before the period?

It would match:
foo.txt
foobar.log

It would not match:
foo.bar.txt
abc.txt

I'm going to use this inside an if-statement in a ksh script, if that makes any difference.

ls | awk -F\. 'NF==2'

Regards

That doesn't remove filenames containing abc..

(And there's no need for ls.)

printf "%s\n" * | awk -F\. 'NF==2 && !/abc\./'

That will not pick up filenames that begin with a dot.

Oops, I missed that.

Regards

That works wonderfully, thanks! In case anyone cares, here's the final code (with private details omitted), once put inside a for-loop and if-statement. Maybe not the best way, but it works...

for file in *; do
  if [[ `echo $file | awk -F\. 'NF==2 && !/abc\./' | wc -l` -ge 1 ]]; then
    #do something
  fi
done