質問

How can i rename a directory by interchanging the digits and word in directory name.

e.g. FRA-DEV_007583-K4C-rdf-1
FRA-DEV_007583-K4C-source-8 FRA-DEV_007584-K4C-rdf-19 FRA-DEV_007584-K4C-rdf-8

output should be

FRA-DEV_007583-K4C-1-rdf
FRA-DEV_007583-K4C-8-source FRA-DEV_007584-K4C-9-rdf FRA-DEV_007584-K4C-8-rdf

役に立ちましたか?

解決

If you have all those files in the same directory, with no other files in there, you could use this script:

#! /bin/bash

nums=(`ls $1 | cut -d- -f5`)
words=(`ls $1 | cut -d- -f4`)
files=(`ls $1 | cut -d- -f1-3`)
complete_files=(`ls $1`)

len=${#complete_files[@]}

for (( i=0; i<${len}; i++ ));
do
  newname=${files[$i]}-${nums[$i]}-${words[$i]}   
  mv $1${complete_files[$i]} $1$newname
done

Save this script as rename.sh in a directory OUTSIDE of the one where your files are. Then execute: bash rename.sh path/to/your/files/ don't forget the final slash, and make a backup first just in case.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top