Skip to content

Instantly share code, notes, and snippets.

@r8or0pz
Last active August 29, 2015 14:07
Show Gist options
  • Save r8or0pz/250b1a44afbd27b1a1fc to your computer and use it in GitHub Desktop.
Save r8or0pz/250b1a44afbd27b1a1fc to your computer and use it in GitHub Desktop.
#!/bin/bash
search="$1"
replace="$2"
target_dir="$3"
[ -n "$search" ] || \
{ echo "search is empty"; exit 1; }
[ -n "$replace" ] || \
{ echo "replace is empty"; exit 1; }
[ -n "$target_dir" ] || \
{ echo "target_dir is empty"; exit 1; }
[ -d "$target_dir" ] || \
{ echo "\"$target_dir\" directory is missing"; exit 1; }
grep -rl "$search" "$target_dir" | \
xargs sed -i "s/$search/$replace/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment