LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-01-2005, 09:20 AM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
storing text in a text file for a specified length of time.


Is there anyway to store text in a text file for a specified length of time? For instance, writing something to a text file and the erasing it two weeks after it was entered.
 
Old 08-01-2005, 09:40 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Put a timestamp on each line of the text file
Code:
23-JAN-2004 14:23 <text goes here>
22-JAN-2004 16:12 <text goes here>
Then run a process to identify "old" date and strip them out
 
Old 08-01-2005, 09:47 AM   #3
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
How do you put a timestamp on a line?

Also what would the process look like to identify the old date?
 
Old 08-02-2005, 07:19 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,287

Rep: Reputation: 173Reputation: 173
you can timestamp a file:
touch -t 200501311133 stamp_file (31st jan 2005 11:33)

then use something like

find * -older stamp_file | xargs rm

which finds files older than the timestamp.
 
Old 08-02-2005, 09:14 AM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
I think we don't understand what you want -

Do you want to delete lines of text in one file
or
delete a whole file?
 
Old 08-02-2005, 09:20 AM   #6
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Rep: Reputation: 121Reputation: 121
He's using VB.net and not Linux, I think...
 
Old 08-02-2005, 09:48 AM   #7
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I have figured out how to add dates but I still dont know how to compare them.

I want to compare the dates that they were entered into thew text file with the date of the prsent day. If they have been in the text file for more than a week I want to delete them.

Can anyone help me with this?
 
Old 08-02-2005, 10:27 AM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
I assume you are using VB .Net for this since you were for your other questions, so here's a quick description of what you could do.
  • Read in the whole file into an ArrayList, reading it in one line at a time and adding each line as an element of the array.
  • After the file is read into the array, go through each element of the array. For each line extract the date part. (How you do this depends heavily on the format of the date you use and the way the rest of the line looks, if you are using comma-delimited fields for example, a simple string.split should suffice.)
  • Convert the date string to a DateTime object using the DateTime.Parse method.
  • Compare the newly created DateTime object with a DateTime object representing the oldest entry you want to keep.
  • If the date you read in is older than the dates you want to keep, remove that line from the array list
  • Continue the last few steps above until you've compared all entries in the file
  • When done, re-write your file to disk with only the remaining entries in your ArrayList

I leave converting that into code to you...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which light text editor can copy text from file and paste in browser? davidas Linux - Software 9 03-06-2006 11:28 AM
sending data to standard out and to a text file at the same time. liguorir Linux - Software 1 08-23-2005 12:14 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Replace text of unknown content with other text in file brian0918 Programming 15 07-14-2005 09:22 PM
Replace text of unknown content with other text in file brian0918 Linux - Software 1 07-14-2005 03:22 PM


All times are GMT -5. The time now is 05:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration