-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.sh
executable file
·46 lines (39 loc) · 1.41 KB
/
rename.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RESET='\033[0m'
# Function to replace keywords in files within a directory
replace_keywords() {
local dir="$1"
local old_keywords=("rhodeus" "Rhodeus" "RHODEUS")
local new_keywords=("newprojectname" "NewProjectName" "NEWPROJECTNAME")
# Loop through each file in the directory
for file in "$dir"/*
do
# Check if the file is a regular file
if [ -f "$file" ]; then
# If file is current file then skip
if [ "$file" == "./rename.sh" ]; then
continue
fi
echo -e "${BLUE}Processing file: $file${RESET}"
# Loop through each old keyword and its corresponding replacement
for ((i=0; i<${#old_keywords[@]}; i++))
do
# Check if the file contains the old keyword
if grep -q "${old_keywords[$i]}" "$file"; then
# Print the line number that contains the old keyword
grep -n "${old_keywords[$i]}" "$file"
fi
# Perform the replacement using sed
sed -i "s/${old_keywords[$i]}/${new_keywords[$i]}/g" "$file"
done
elif [ -d "$file" ]; then
# If the file is a directory, recursively call replace_keywords
replace_keywords "$file"
fi
done
}
replace_keywords "."