mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 122
O
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
alright at the moment i got a script thatll record the date and time something is said to a txt file with the nick's name.

Tue Jan 31 22:31:59 2006 ~ Bla Bla Bla Bla

and there r actually many many entries for each day

so this 1 particular file has entries from Jan 31 to now Mar 06

however all i really need in the file is the past 15 days (so if were talking about it from the current day, March 06) - i only need the bit from 19 Feb Onwards, but i actually still have from Jan 31...

so what i wanted to do was a script that either automatically cut off the useless info from ALL txt files in a particular folder, or when triggered, would cut off the useless info from the specific txt file. i.e by alias /trim NICK (So Nick.txt)

now im not exactly positive on how to do this, i dont particularly want to create a whole bunch of if events, and go $read through the file lots of times, so does anyone else have an idea?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Read the line into a variable
Convert the first 5 entries using $ctime (this will give you the ctime equivalent of the date & time recorded in the file)
subtract that from today's date & time ($ctime)
if the difference is greater than 15 days, then delete the line from the text file.

This is based upon the information being written to the text file in the format you have shown, and is just a suggestion.

Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
You could use /filter -k to send each line to an alias, this alias would then check if the date is within the last 15 days, if it isn't then the alias dose nothing, otherwise if it is it will write the line to a new file. Then delete the old and rename the new to the name of the old file.

Assuming lines are written in order of top to bottom oldest to newest, you could add a variable that would be set the first time it finds a line that SHOULD be written to the new file, so that proceeding lines sent to the alias would just check for the variable and write to the new file, rather than perform the slower calculation unneccersarily. (the variable would be unset after the filter has finished running on that file).


"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I would just filter the last 15 days and today into an output file. (i would need to use 16 filters to do this becuase i suck at regex, but im sure someone could write a regex that would match it in one filter) <hint hint>

Since internal filters run damn but alot faster i would say doing 16 of them might out strip using -k and checking each line.


Link Copied to Clipboard