Tuesday, August 08, 2006

Script to help clean out log files

I wrote a short script that helps me clean out log files. I don't care that other scripts exists for this. This is for ME to learn the ins and outs of writing scripts from scratch.

#Script to ask for input, then delete that string from a file
#Command to get string to be deleted
echo "Enter string to be deleted :"
read delstring

#uses the requested input in a script to delete from a file, moves the file to another file then back to the original file so that it doesn't blank out the original file

sed /$delstring/d file1 > file2; mv file2 file1



I added an addition line to ask for the file to be modified. Changes are in red

##Script to ask for input, then delete that string from a file
#Command to get string to be deleted
echo "Enter string to be deleted :"
read delstring

echo "Enter filename to be modified :"
read modfile

#uses the requested input in a script to delete from a file, moves the file to another file then #back to the original file so
#that it doesn't blank out the original file
sed /$delstring/d $modfile > file2; mv file2 $modfile

0 Comments:

Post a Comment

<< Home