bash - Shell script to get one to one map and rename the filename -


i have 2 files sorted numerically. need shell script read these 2 files , 1:1 mapping , rename filenames mapped case#;

for example:

cat case.txt 10_80 10_90  cat files.txt bcd_x 1.pdf bcd_x 2.pdf  ls pdf_dir bcd_x 1.pdf bcd_x 2.pdf 

read these 2 txt , rename pdf files in pdf_dir :

a bcd_x 1.pdf bcd_10_80.pdf bcd_x 1.pdf bcd_10_90.pdf 

if have bash 4.0 help:

#!/bin/bash  declare -a map i=0 ifs=''  while read -r case;     (( ++i ))     map["a bcd_x ${i}.pdf"]="a bcd_${case}.pdf" done < case.txt  while read -r file;     __=${map[$file]}     [[ -n $__ ]] && echo mv "$file" "$__"  ## remove echo when things seem right already. done < files.txt 

note: make sure run script in unix file format.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -