#!/bin/bash # Set the name of the text file to search for file=$(find . -name "application.conf" -type f) file2=$(find . -name "mongod.conf" -type f) # Set the pattern to search for in the file PATTERN='connectionString = "mongodb://"${mongodb}":27017"' PATTERN2='mongodb = "localhost"' PATTERN3='#security:' SPACES="\\" # Set the replacement string REPLACEMENT='connectionString = \${credentials}' REPLACEMENT2='credentials="mongodb://ambienceUser:Letmein2021@"${mongodb}":27017"' REPLACEMENT3='security:' REPLACEMENT4=" authorization: enabled" # Check if the text file exists if [ -f "$file" ]; then echo "Text file found: $file" # Search for the pattern in the text file if grep -q "$PATTERN" "$file"; then echo "Keyword found in text file: $PATTERN" # Replace the pattern with the new string using sed sed -i "s|$PATTERN|$REPLACEMENT|g" $file sed -i "/$PATTERN2/i $REPLACEMENT2" $file echo "Keyword replaced with: $REPLACEMENT" else echo "Keyword not found in text file" fi else echo "Text file not found: $file" fi if [ -f "$file2" ]; then echo "Text file found: $file2" if grep -q "$PATTERN3" "$file2"; then echo "Keyword found in text file: $PATTERN3" sed -i "s|$PATTERN3|$REPLACEMENT3|g" $file2 sed -i "/$REPLACEMENT3/a $SPACES$REPLACEMENT4" $file2 echo "Keyword replaced with: $REPLACEMENT3" echo "Keyword added: $REPLACEMENT4" else echo "Keyword not found in text file" fi else echo "Text file not found: $file2" fi