Write a Bash script that searches for all HTML files in a directory and its…
- User
Write a Bash script that searches for all HTML files in a directory and its subdirectories and replaces the occurrences of "old text" with "new text". The script should prompt the user for confirmation before making any changes and should log all changes made into a file named "replace.log".
- Assistant
Here is an outline of a Bash script that searches for all HTML files in a directory and its subdirectories and replaces the occurrences of "old text" with "new text":
- Prompt the user for confirmation before making any changes:
shwhile true; do read -p "Are you sure you want to replace all occurrences of 'old text' with 'new text'? (y/n): " confirm_text case $confirm_text in y) break; n) echo "Please enter 'y' for yes or 'n' for no."; continue; esac done 2. Search for all HTML files in the directory and its subdirectories: ```sh export PATH=$PWD/:$PATH find . -name "*.html" -exec sed -i "s/old text/new text/" {} \; 3. Log all changes made: ```bash cat replace.logThis script uses
readto read user input for confirmation (in this case, "y" for "yes" and "n" for "no"), and acasestatement to handle the user's input. For each HTML file found, the script uses to replace all occurrences of "old text" with "new text". The changes are logged to a file named "replace.log" using .