I dont need to delete files that are old, but the contents inside a file that are 30 days old. We can check the date and delete lines that are date pattern older than 30 days.
Get the current date store it in a variable
While you read a file using Readdir,
open a file handle
start reading a file using that file handle (read by line)
Now keep copying the content of file into another bkp file until you reach the day which is 30 days older from today (refer my second line)
once that is done close FH, and unlink the file (delete it) and name the bkp file as originial one.
End of while loop.
Let me know how that works out - if you didn't get it send me sample file I'll write a small script demonstrating how to do that.