bash function to search and replace in all files with special extension recursively
Pretty much, the code is below. It is a part of my function collection for the bash.
####
# Replaces a string in all files in given path and below
# taken from: http://www.cyberciti.biz/faq/unix-linux-replace-string-words-in-many-files/
# taken from: http://stackoverflow.com/questions/4437901/find-and-replace-string-in-a-file
# taken from: http://stackoverflow.com/questions/7450324/how-do-i-replace-a-string-with-another-string-in-all-files-below-my-current-dir
#
# @author stev leibelt
# @since 2013-7-30
####
function net_bazzline_replace_string_in_files ()
{
if [[ $# -lt 3 ]]; then
echo 'invalid number of arguments provided'
echo 'command search replace fileextension [path]'
return 1
fi
if [[ $# -eq 4 ]]; then
find "$4" -name "*.$3" -type f -exec sed -i 's/'"$1"'/'"$2"'/g' {} \;
else
find . -name "*.$3" -type f -exec sed -i 's/'"$1"'/'"$2"'/g' {} \;
fi
}
Kommentare
Ansicht der Kommentare: Linear | Verschachtelt