Advertisement

04.14.2008 at 04:48PM PDT, ID: 23322271
[x]
Attachment Details

Powershell reading, selecting and cutting lines

Asked by artur_dietrich in Scripting Languages, Microsoft Windows Operating Systems, VB Script

Tags: Microsoft, Windows 2003 Script, PowerShell, VBS

Hi!

I need a script in Powershell or VBS to read a text file (TEST.TXT) and cut off lines that have a pre-defined "date field" older than Actual Date - "N" days. Better: I want keep in file, just the lines with
"date field" of the last "N" Days. A new file can be generated TEST.NEW.
(Obs:
1) format date: dd/mm/yy
2) Lines are in date-order
)

Example: KEEP just the lines with "date field" newer than 10 ten days ago.

Current date = 14/04/08
Day offset = 10
So, keep lines with "date field" newer than 04/04/08 (14/04/08 - 10 days = 04/04/08)

Content of TEST.TXT:

"01/03/08 18:32:32","Any String 1","Other String", "And Another 1"
"02/04/08 18:32:32","Any String 2","Other String", "And Another 2"
"03/04/08 18:32:32","Any String 3","Other String", "And Another 3"
"10/04/08 18:32:32","Any String 4","Other String", "And Another 4"
"14/04/08 18:32:32","Any String 5","Other String", "And Another 5"

Content of resulting file TEST.NEW

"10/04/08 18:32:32","Any String 4","Other String", "And Another 4"
"14/04/08 18:32:32","Any String 5","Other String", "And Another 5"

Best Regards,
Artur
Start Free Trial
[+][-]04.15.2008 at 07:10AM PDT, ID: 21358832

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 10:41AM PDT, ID: 21360858

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Scripting Languages, Microsoft Windows Operating Systems, VB Script
Tags: Microsoft, Windows 2003 Script, PowerShell, VBS
Sign Up Now!
Solution Provided By: BSonPosh
Participating Experts: 2
Solution Grade: A
 
 
[+][-]04.23.2008 at 07:04AM PDT, ID: 21420772

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628