www.pudn.com > txtdel.rar > txtdel.sh
#!/bin/sh
flag=0
if [ $# -eq 0 ]
then
for ii in `ls`
do
if [ "${ii##*.}" = "txt" ]
then
flag=$(($flag+1))
fi
done
#if [ `ls *|wc -l ` -lt `touch 1.txt && ls *|wc -l` ]
if [ "$flag" -eq 0 ]
then
echo "Error! The directory does not contain any files witn a .txt extension"
echo
else
for i in ` ls *.txt`
do
echo File : $i
head -n 3 $i|awk '{ print NR ": " $0 }'|sed 's/^/Line /'
echo -n "Delete ? Y|N: "
read a
if [ "$a" = "Y" ]
then
rm $i
echo "File $i has been deleted "
elif [ "$a" = "N" ] ; then
echo "File $i was NOT deleted "
fi
echo
done
fi
fi
while [ $# -gt 0 ]
do
if [ ! -f `pwd`/$1 ]
then
echo "Error! File $1 does not exist in the directory "
echo
elif [ ${1##*.} = "txt" ]
then
echo "File: $1"
head -n 3 $1|awk '{ print NR ": " $0 }'|sed 's/^/Line /'
echo -n " Delete ? Y|N "
read a
if [ "$a" = "Y" ]
then
rm $1
echo "File $1 has been deleted "
elif [ "$a" = "N" ] ; then
echo "File $1 was NOT deleted "
fi
echo
else
echo "Error! Unable to process $1.I can only deleted files witn .txt extnsion"
echo
fi
shift
done
echo "No more .txt file to process. Finished!"
echo