There's a folder with two files in it like: filename-3.0.1-extra.jar
and filename-3.0.1.jar
. The number and dots in the middle are the version, which can change. I'm trying to copy filename-3.0.1.jar
to another folder.
Something like:
cp folder1/filename-*.jar otherfolder/
But the wildcard *
matches both files. I'm trying to copy just the file without the -extra
at the end. So I'm trying to match filename on just numbers and dots when I copy, something like this:
cp folder1/filename-[0-9.].jar otherfolder/
.
But that's not the right syntax for the regex. Would appreciate any help here!
CodePudding user response:
Using extglob
you can do this:
shopt -s extglob
cp folder1/filename- ([0-9.]).jar otherfolder/
Here ([0-9.])
will match 1 or more of any digits or dots.
CodePudding user response:
you can do something like
cp "folder1/${##*.}" otherfolder
or
cd folder1 && cp -r -v $(echo -e $(ls | grep -e "[0-9]*\.*")) otherfolder/. && cd ..