Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Read the old substring from user input
- read -p "Enter the substring to replace: " old_substring
- # Read the new substring from user input
- read -p "Enter the new substring: " new_substring
- # Loop over all files in the current directory that contain the old substring
- for file in *"$old_substring"*; do
- # Rename the file by replacing the old substring with the new substring
- # The string manipulation uses parameter expansion
- # this method allows a regex-like string manipulation
- new_file="${file/$old_substring/$new_substring}"
- mv -- "$file" "$new_file"
- # Echo the new file name
- printf "$file\t->\t$new_file\n"
- done
Advertisement
Add Comment
Please, Sign In to add comment