powershell - How do I replace dates in multiple textfiles at fixed positions, but only when the original date is from the past month -


I'm getting better in the script in PowerShell, but I'm still a newbie and I find a solution for this one There is a problem in the

I have a group of text files (without ending) exported from a financial system in an "in" folder. The contents of the content always have the same structure and length.

The status is a date in format yymmdd on the 72-77 character of every line. I dated the need to replace it with a fixed price: write all modified files in YY = actual year mm = actual month, DD = 01, but only if the original date is the last month that I have an "out" folder

How the data will appear:.

  00201079980000000000000000007719308672900000286850040040014092914092914093000923000100000000000000  

I as average place in September (09) "140 930" already passed with "141001" (character positions 72-77) Is required.

certainly ways to do this in PowerShell, and I (and many others) While writing the script may help, it is suggested that I could download it PowerShell Community Extensions. Now this (24 October 2014) contains a CMDlet which is included in the editing file, which does exactly what is right for you. It can be as simple as:

  get-childitem c: \ path \ to \ files \ *. Txt | Where {(content obtained $ _ integer-total number 1). Asbestring (73,2) -lt (received-date-"mm")} | Edit File -pattern '(? (& Lt.; = ^ {71}) \ d {6}) (s?)' ( "YyMM01" -f Go date) -replacement Force  

Comments