I have a list of files which have number prefixes e.g 1-filename.txt
2-filename.txt
..so on . I found that I skipped a file name as 45-filename.txt
. I have files from 1-filename.txt
to 100-filename.txt
in that directories . Now I want to rearrange all the files with number prefixes without losing their actual name(e.g filename.txt) by creating a bash script but failed to do that. The script I have created as below.
#!/bin/bash
n=1
for i in *.txt;
do
file=$(ls -v "$i" | awk -F- ' { print $NF }')
mv $i "$n-${file}"
let n=n+1
done
But I am not getting required output.
note files have spaces in its name e.g : 1-my first file.txt
2-my second file.txt
....so on.