Skip to content

Instantly share code, notes, and snippets.

@remyd1
Created January 26, 2017 11:05
Show Gist options
  • Save remyd1/96fd870575c54c7785ff2afd4829a870 to your computer and use it in GitHub Desktop.
Save remyd1/96fd870575c54c7785ff2afd4829a870 to your computer and use it in GitHub Desktop.
M-[BC]M- remover
#!/bin/bash
#############################################################################
# SCRIPT: $0
# DESCRIPTION:
# This script will be able to detect hidden caracter "M-[BC]M-...",
# And/Or remove this !
# REVISIONS:
# 2014/06/11 YG
# UPDATE:
# 2016/03/29 remyd1
#____________________________________________________________________________
#
# PARAMETERS:
# > $1 :TARGET, (e.g. '"*.sh"' )
# > $2 :ACTION, (e.g. 'remove' )
# > $2 :BACKUP, (e.g. '' )
#
#############################################################################
usage="$0 file remove|show [backup]"
if [ "$#" -lt 2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ];then
echo $usage
exit 1
fi
TARGET=$1
ACTION=$2
BACKUP=$3
if [ "$TARGET" = "" ]
then
echo 'Need to choose target file'
echo 'M-BM-Remover [TARGET] [show/remove] [backup]'
echo 'Example : M-BM-Remover "*.sh" remove backup'
exit
fi
echo "ACTION = $ACTION";
echo "TARGET = $TARGET";
echo
if [ "$ACTION" = "show" ]
then
for file in $TARGET
do
if [ "$file" != "M-BM-Remover.sh" ]
then
echo "Traitement de $file ..."
cat -v $file | egrep M-[BC]M-
NB=`cat -v $file | egrep M-[BC]M- | wc -l`
echo "Occurence(s) : $NB line"
fi
done
fi
if [ "$ACTION" = "remove" ] || [ "$ACTION" = "" ]
then
for file in $TARGET
do
if [ "$file" != "M-BCM-Remover.sh" ]
then
echo "Traitement de $file ..."
NB=`cat -v $file | egrep M-[BC]M- | wc -l`
cat $file > $file.bak
cat -v $file.bak | sed -r "s#M-BM-##g;s#M-CM-[\)\(\*\+]#e#g;s#M-CM-4#o#g;s#M-CM-'#c#g;s#M-CM- #a#g;s#M-CM-[\.\/]#i#g;s#M-CM-9#u#g" > $file
echo "Occurence(s) removed on $NB line(s)"
if [ "$BACKUP" != "backup" ]
then
rm -f $file.bak
fi
fi
echo
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment