I need to remove a serial number in my file name which is between - and _ (the underscore should also be removed).
Original file name : 20190815-12345_table_file.rar
Expected : 20190815-table_file.rar
My bash code :
for f in ./*.rar;
do fn=`echo $f|sed 's/^-[0-9].*_$/-/g'`;
mv "$f" "$fn";
done;
I tried something like this because i know that my numbers are starting with "-" (so ^) are numbers ([0-9].*) and are ending with "_" (so $) and I want to replace numbers by "-".
But with this method it doesn’t work.