I need to delete the content out of a number of logs

I'm just starting out in scripting (taking online classes) but I need to know how to clean out (delete) the content of a number of logs. All of the files end in 'trc'. Does anyone have a script or command (SED or AWK) I can use?

Julie

The best way to learn scripting is to get on the command line and try a few things! This script trims a log and removes others. Be patient and you will learn. Also, take a look at the board rules, no posting homework questions!

#!/bin/ksh
# name: cleanup
# this is a genral cleanup script
echo "starting cleanup...wait"
rm /usr/local/apps/log/*.log
tail -40 /var/adm/mesages >/tmp/messages
rm /var/adm/messages
mv /tmp/messages /var/adm/messages
echo "finished cleanup"

Thanks for the reply. (This is a work question). I need to remove the content of multiple logs within a directory but not the log itself. Processes are conected and if I remove the logs I have Inode issues. So, I was hoping to find a script or command that would allow me to use a wildcard and would remove the content of the logs.

Thanks

Julie

A point to be careful of here.

Simply removing entries from a log file or removing a log file whilst its logging process is still running might not release disk space.

You may have to stop and restart the logging process (whatever that process is) before the disk space is available for other uses and other processes.

If you want the remove the contents of the logs without removing the file itself then echo a blank to the log, but dont append to the log, overwrite the log instead. This will overwrite all contents of the log with a blank space. The result is an empty log.

for $LOG in ` ls -1 /log-path/*.trc`
do
echo "" > $LOG
done