We regularly have images that are named 1234567890_GH_ANI_EPS.eps with variables after the first underscore. I would like to write a bash script to remove the first underscore up to the file extension.
Original file name: 1234567890_GH_ANI_EPS.eps New File Name: 1234567890.eps
I was able to achieve removing the last _EPS by using the below code:
for f in "$@"
do
mv "$f" "${f%_*}.eps"
done
And have tried the below and the file disappears:
for f in "$@"
do
mv "$f" "${f%%_*}.eps"
done
any help would be appreciated. Thank you
${f%%_*}.eps
to match from the first underscore instead of the last one.${f%%_*}.eps
the file dissapears, and am not sure what is happening to it.a="1234567890_GH_ANI_EPS.eps"
=>echo $(echo $a | cut -f1 -d"_").$(echo $a | cut -f2 -d".")
$()
runs a subshell;cut
is implemented by a whole new executable. Andecho $a
(as opposed toecho "$a"
) has its own bugs.