Skip to content

Instantly share code, notes, and snippets.

@amaalali
Created September 6, 2019 15:40
Show Gist options
  • Save amaalali/91172d835d0c743b5d95f4cbf9db8575 to your computer and use it in GitHub Desktop.
Save amaalali/91172d835d0c743b5d95f4cbf9db8575 to your computer and use it in GitHub Desktop.
Bash script with awk to replace text in files
#!/bin/bash
echo "Applying changes"
echo ""
declare -a arr=(
"file1"
"file2"
)
for file in "${arr[@]}"
do
echo "Start File: $file"
awk '/<-- Text For Search Goes here -->/{gsub(<-- Text For Search Goes here -->, "<-- Text to replace here -->")};{print}' $file > tmp && mv tmp $file
echo "End File: $file"
echo ""
done
echo "Changes complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment