14 May, 2010, Bojack wrote in the 1st comment:
Votes: 0
Im trying to come up with a way to search through player files, and match a line then take that line argument, make it an integer and see if its greater than a specific number. If it is itll delete the file. Runter was helping with this and made a script in ruby which I went off of, since I cant install ruby right now I tried converting it my way into bash but now need some help. This is what I got so far which DOES NOT work right.
#!/bin/bash
#power level check
#output=""

for f in *
do
if [ -f $f ]
then
output=$f
size=$(ls -l "${f}" | awk '{ print $5}')
file=$(size)
fi
if [ -r $file ]
then
exec 3<&0
exec 0<"$output"
while read -r line
do
found=`expr match "$line" '(/^Plvl (\d+)/)'`
if [[ $found =~ $line ]]
then
lvl=`expr match "$found" '(\d+)/)'`
lvl=${BASH_REMATCH[*]}
MIN=$lvl
MAX=10000
fi
if [[ $MIN -ge $MAX ]]
then
echo "Found match, Deleting File: $output"
rm -f $output
fi
done
exec 0<&3
fi
echo $file
done

My problem is it just spits out this: size: 'a.out': No such file
14 May, 2010, quixadhal wrote in the 2nd comment:
Votes: 0
First, I'll say that deleting player files is bad in these days of giant disks that would hold a billion of them….

But, if you're going to anyways… why not have your MUD do it? It already knows how to read them.
14 May, 2010, Runter wrote in the 3rd comment:
Votes: 0
Answer is install Ruby. :p
14 May, 2010, quixadhal wrote in the 4th comment:
Votes: 0
perl
14 May, 2010, Runter wrote in the 5th comment:
Votes: 0
quixadhal said:
perl


But I already wrote the script for him in Ruby to do what he wants. He just has to install Ruby to use it. :p
14 May, 2010, quixadhal wrote in the 6th comment:
Votes: 0
No need for fancy scripts….

This will print filenames and level numbers that exceed 50
egrep -r -e 'Plvl[ ]+[0-9]+' . | awk "{if(\$2 > 50) {printf(\"%s %s\\n\", \$1, \$2);}}" | sed 's/:Level//'

If you wanted to remove those files, but be careful!
egrep -r -e 'Plvl[ ]+[0-9]+' . | awk "{if(\$2 > 50) {printf(\"%s\\n\", \$1);}}" | sed 's/:Level//' | xargs rm


Be sure you make backups, and if this nukes all your players, it ain't my fault. Test and fiddle until it does what you want.
15 May, 2010, Bojack wrote in the 7th comment:
Votes: 0
Thank you quix, I knew it could be done with one of the grep functions just didnt know how.
Ran into a problem with your second one though, xargs is spitting out what egrep gives which would be ./Titan:Plvl whic is the $1 argument.
15 May, 2010, Bojack wrote in the 8th comment:
Votes: 0
Nevermind I fixed it, sed needs to be this sed 's/:Plvl//'
15 May, 2010, Bojack wrote in the 9th comment:
Votes: 0
I found another method btw, I took your method and added it into a bash script to see the count difference:
#!/bin/bash
echo "Checking player files…"

count=0
amount=0
for f in *
do
if [ -f $f ]
then
output=$f
((count++))
matched=$(egrep -e '^Plvl[ ]+[0-9]+' "${f}" | awk "{if(\$2 <= 10000) {printf(\"%s\\n\", \$f);}}")
if [[ $matched ]]
then
((amount++))
fi
fi
done

echo "Found $amount matched files out of $count files"
0.0/9