Supprimer les commentaires d'un fichier.

From Tuxunix
Jump to: navigation, search
#!/bin/sh
 
#
#@Name		skip-comment.sh
#@Date		11/04/2007
#@Note		Delete commentary on start ligne
#@Author	TuXedo
#@Version	0.1
#
 
 
function deleteLigne(){
 
SAVEFILE="/tmp/$(basename $file).tmp"
echo "FILE ORIG : ${file}"
echo "TMP : $SAVEFILE"
cp ${file} $SAVEFILE
 
sed '/^#/d' $SAVEFILE > $file
 
[ "$?" == "0" ] && {
	echo "Delete Comment [Done]."
	} || {
	echo "Delete Comment [Error]."
	}
 
} #deleteLigne
 
 
function main(){
 
if [ -z ${1} ]; then
	echo "use -h or --help";
	exit 0
fi
 
case "${1}" in
	-h | --help)
	echo "Delete commentary ligne!!"
	echo "Usage ${0##/} [file_name]"
	;;
	*)
	if [ -f $1 ]; then
		file=${1}
		echo "FILE : $file."
		deleteLigne
	else
		echo "Error file_name!!"
	fi
	;;
esac
 
} #main
 
main $@