How to get wildcard portion of filename in Bash

Viewed 6191

This question may have already been asked, but I don't know how to word it well. I'm new to bash scripting...

Suppose I have a bunch of files in a directory with names like:

file1_pre.ext
file2_pre.ext
file3_pre.ext
different_tmp.ext

I can use a use a wildcard to filter the files of interest:

for f in *_pre.ext
do
   echo $f
done

But how do I parse/extract the prefixes so that I can get strings file1, file2, etc. to use as filenames for something else?

1 Answers
Related