anonymiser.sh 1.04 KB
Newer Older
1
#!/bin/sh
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

# A special file with the list of words to replace. The format is one word per line, with a tabulation as separation
# Example:
# name	offuscatedname
# phonenumber	111111
anonymise_list="Anonymiser"

# Take the folder to anonymise as argument, and check if it is a folder
if [ $# -gt 0 ] && [ -d $1 ]
then
	dossier=$1
else
	echo "Usage: $0 FOLDER"
	echo "For example : $0 /tmp/weboob_session_NLSIls/freemobile/"
	exit 1
fi

if [ ! -f $anonymise_list ] 
then
	echo "Please create the $anonymise_list file (see documentation)"
	exit 1
fi

# remove potentials old files
find $dossier -name \*_anonymised -delete
rm -rf $dossier/Anonyme

for file_to_anonymise in `find $dossier -type f`
do
	file=$file_to_anonymise"_anonymised"	
	cp $file_to_anonymise $file
	
	cat $anonymise_list | tr '\t' '_' | while read line
	do
		to_replace=$(echo "$line"|cut -d_ -f1)
		replace_with=$(echo "$line"|cut -d_ -f2)
		sed -i "s%$to_replace%$replace_with%Ig" $file
	done 
done
mkdir $dossier/Anonyme

find $dossier -name \*_anonymised -exec mv \{\} $dossier/Anonyme \;