I need to match results of find
with regexp. The files are as:
/path/1/file1.001.txt
/path/1/file2.001.txt
/path/1/file1.001
/path/2/file3.002.txt
/path/2/pure_file3.002.txt
etc.
I need to match all files from all directories ending in xxx.txt
where xxx
are 3 digits and only those filenames that are not preceded by word pure_
. Further, I need to return the full path.
I have all working except excluding the files preceded by pure_
:
find /path/ -mindepth 1 -maxdepth 2 -type f | grep -P '.*\.[0-9]{3}.txt'
I tried:
find /path/ -mindepth 1 -maxdepth 2 -type f | grep -P '.+(?!pure).*\.[0-9]{3}.txt'
but if I do in say /path/1/
:
ls -1 | grep -P '^(?!pure).*\.[0-9]{3}.txt'
that correctly excludes those files, on the other hand:
ls -1 | grep -P '(?!pure).*\.[0-9]{3}.txt'
does not.
So it probably boils down to, how to match within a full path a basename that does not start with pure_
. My understanding of regular expressions is insufficient for that, it may have something to do with the atomicity of look arounds which i never understood.