-1

I have this file name

1006_12_000123123_000023126.data

and I want this file name. I have arround 300000 files.

1006_12_123123_23126.png

I tried som of these solution, but they are for filename like 00002323.jpg

Bash command to remove leading zeros from all file names

I can use mv to rename.

Community
  • 1
  • 1
Maros Mayer
  • 67
  • 1
  • 7

2 Answers2

2
for original_name in *.data; do
    # determine new file name from original:
    # remove zeroes and change extension.
    new_name=$(echo "$original_name" | sed -e 's/_0*/_/g' -e s'/.data$/.png/')
    mv "$original_name" "$new_name"
done
ron rothman
  • 17,348
  • 7
  • 41
  • 43
0

Use this

ls * | sed -e 'p;s/_0*/_/g' | xargs -n2 mv
Eduardo Escobar
  • 3,301
  • 2
  • 18
  • 15