Skip to content
Snippets Groups Projects
Commit 69965922 authored by Andy Yates's avatar Andy Yates
Browse files

Allow for multiple dirs to be given

parent 61f1ef22
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
function confirm()
{
echo -n "$@ "
read -e answer
for response in y Y yes YES Yes Sure sure SURE OK ok Ok
do
if [ "_$answer" == "_$response" ]
then
return 0
fi
done
return 1
}
year=$(date "+%Y")
last_year=$(($year - 1))
search="Copyright (c) 1999-${last_year}"
replacement="Copyright (c) 1999-${year}"
confirm "About to scan $(pwd) for files to replace '$search' with '$replacement'. Ok?"
for file in $(grep -R --files-with-matches "$search" .); do
echo "Replacing date in $file"
sed -i "s/$search/$replacement/g" $file
done
if [ -z "$@" ]; then
dirs=$(pwd)
else
dirs=$@
fi
original_wd=$(pwd)
for var in "$dirs"; do
if [ ! -d $var ] ; then
echo "$var is not a directory. Skipping"
continue
fi
cd $var
year=$(date "+%Y")
last_year=$(($year - 1))
search="Copyright (c) 1999-${last_year}"
replacement="Copyright (c) 1999-${year}"
echo "About to scan $(pwd) for files to replace '$search' with '$replacement'"
for file in $(grep -R --files-with-matches "$search" .); do
echo "Replacing date in $file"
sed -i '' -e "s/$search/$replacement/g" $file
done
cd $original_wd
done
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment