[CentOS] Bash Script for Beginners! oh dear :'(
Alexander Dalloz
ad+lists at uni-x.org
Tue Dec 23 14:23:18 UTC 2008
James Bensley schrieb:
> For those interested here is an updated version of my script but still
> no luck :(
>
> #!/bin/bash
> rm -f ./found_files
> touch ./found_files
> find . -exec grep -q "$1" '{}' \; -print >> ./found_files
> i=1
> while [ $i -le `wc -l found_files` ] ; do
> line=`head -$i found_files | tail -1`
> grep -iv "$1" $line > $line.new
> rm $line
> mv $line.new $line
> i=`expr $i + 1`
> done
How about following:
#/bin/sh
DIRECTORY="/root.dir.path.of.the.blacklists"
PATTERN=$1
if [ "${PATTERN}" = "" ]; then
echo "parameter missing - stop"
exit 1
fi
if [ ! -d "${DIRECTORY}" ]; then
echo "directory missing - stop"
exit 1
fi
while read LINE; do
echo "pattern found in ${LINE}: erasing [${PATTERN}]"
sed -i "s/.*${PATTERN}.*//; /^$/d" ${LINE}
done < <(grep -rl "${PATTERN}" ${DIRECTORY})
exit 0
Greetings
Alexander
More information about the CentOS
mailing list