Author Posts

January 1, 2012 at 12:00 am

by forgotten at 2013-02-26 01:32:32

Hello,
i need help with powershell script since i am totally new in that area.
I need a script tu run once a day.
To look in a txt file and to copy in new txt file all the lines from original txt file that are with previos day date.
the formtatet date in text file is like this:

20130224 ramdom text
20130224 ramdom tex DSFAF
20130224 ramdom text
20130224 ramdom text EFf
20130224 ramdom text
20130225 randim sdadfaef
20130225 jsdjosjfsojfsoa;ja;fj

So if today is 26 of feb. i need the csript to copy all the lines with 20130225 date in new file.
If tehere is no antries for the day in that txt file no action to be performd.

Thank you in advance.

by kittH at 2013-02-26 08:27:28

I think this should do what you're looking for. Let me know if you have any questions.

Get-Content C:\InputFile.txt | Where-Object {$_.StartsWith((Get-Date).AddDays(-1).ToString("yyyyMMdd"))} | Out-File C]

by forgotten at 2013-02-27 01:32:54

[quote="kittH"]I think this should do what you're looking for. Let me know if you have any questions.

Get-Content C:\InputFile.txt | Where-Object {$_.StartsWith((Get-Date).AddDays(-1).ToString("yyyyMMdd"))} | Out-File C][/quote]

Thanks a lot. It works perfect!