0

I have a tool that wants a filename.ext to make a bunch of files, and also wants a directory name to put them in. In my case filename/ would do.

Directory:
Filename1.ext
Filename2.ext

cmd Filename1.ext Filename
cmd Filename2.ext Filename2

I've been trying to tackle it via find, but maybe there is a better way?
find . -iname "*.ext" -exec cmd ... ?

0

2 Answers 2

1

I found a solution, not sure if it is optimal.
find -iname "*.ext" -exec bash -c 'cmd "$1" "${1%.*}"' bash {} \;

This will call cmd filename.ext filename for each matching file

Updated solution with input from ilkkachu, thanks!

1
  • Do you mean to recurse down into subdirectories? (this was not explicitly mentioned in the question) Since you're using -iname rather than -name, does that mean that you expect there to be files with suffixes .Ext, ExT, .EXT, etc.?
    – Kusalananda
    Aug 8, 2021 at 17:47
0

If you know what's the extention of the <filename.ext>, try

for i in *.ext; do cmd "$i" "$(basename -s .ext "$i")"; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .