0

I have multiple files named 01 - a.txt, 02 - b.txt, 03 - c.txt etc. I want to remove the initial number and the dash to have all files named like a.txt, b.txt, c.txt. I'm not good with bash so I would be extremely thankful for some help.

Many thanks!

Turbotanten
  • 386
  • 3
  • 14
  • 4
    This has been [answered](https://stackoverflow.com/questions/20657432/rename-multiple-files-but-only-rename-part-of-the-filename-in-bash) already – ChrisSc Nov 16 '22 at 18:23
  • Not exactly, since this requires a for loop and a conversion of integer to string I believe. – Turbotanten Nov 16 '22 at 18:30

1 Answers1

2

Try substring removal ##*-

E.g.

$ arr=("01 - a.txt" "02 - b.txt" "03 - c.txt")

$ echo "${arr[@]##*- }"
a.txt b.txt c.txt

In a loop

for i in *-*.txt;do echo "$i" "${i##*- }";done
01 - a.txt a.txt
02 - b.txt b.txt
03 - c.txt c.txt

Replace echo with mv if the output looks ok.

Andre Wildberg
  • 12,344
  • 3
  • 12
  • 29