Batch Copy files and Replace content accordingly

#!/bin/bash 

# Read all file names into an array 
FilesArray=($(find . -name "deriv1-clrn*qa.jil")) 

# Get length of an array 
FilesIndex=${#FilesArray[@]} 

# Use for loop read all directory names 
for (( i=0; i<${FilesIndex}; i++ )); 
do 
    source="${FilesArray[$i]}" 
    destination="$(echo "${source}" | sed 's/qa/prod/')" 
echo "cp ${source} ${destination}"     
if [ -f ${destination} ]; then 
rm ${destination} 
fi 
touch "${destination}" 
awk -v destination="$destination" '{a = ($0); b = gensub("qa","prod","g",a); print b >> destination; }' "${source}" 
done 

#awk '{print $0}' $destination 




你可能感兴趣的:(Batch Copy files and Replace content accordingly)