Copy and replace content in the filename line
I am trying to copy a file boot-1.5-SNAPSHOT.jar
to boot-1.5.jar
.
I tried this with help sed
, but I am getting an error. I know the syntax is wrong and I hope someone can fill it in for me.
cp boot-* | sed -e 's:-SNAPSHOT::g'
cp: missing destination file operand after βboot-1.5-SNAPSHOT.jarβ
The idea behind this is that the script will not know the version number, only that the jar will be in the folder where it is trying to copy the file. This is why I am using an asterisk. The version number changes quite often, so using cp file file2
it won't work.
source to share
No need for sed
, use Parameter deployment :
$ file=boot-1.5-SNAPSHOT.jar
$ echo ${file/-SNAPSHOT/}
boot-1.5.jar
or
$ cp "$file" "${file/-SNAPSHOT/}"
In this case:
$ {parameter / pattern / string}
Replacing the template. ... The template is expanded to create as in the path extension. The parameter is expanded and the longest pattern match with its value is replaced with a string.
Note that since you are dealing with files, you must specify variables (otherwise files with whitespace will be corrupted).
It is also possible that a symbolic link should be created instead of a copy:
$ ln -s "$file" "${file/-SNAPSHOT/}"
source to share