Wednesday, 15 August 2012

powershell - remove last 14 digits from string, if there are digits -


I have a text file where I submit my testname. This testname sometimes has a date in which 14 digits There are timestamps. The testname can be:

data-c (festo1-small1); Divider-bin-1.4.4; Nuclear-con-1.3.3-w (1,16); Storage-bin-1.5.4; Storage-cone-1.5.0-W (1); Worker-bin-4.5.5; Worker-con-4.4.1-C (Festo 1) -Wine 1

or

data-c (festo1-small1); Divider-bin-1.4.4; Nuclear-con-1.3.3-w (1,16); Storage-bin-1.5.5; Storage-cone-1.5.0-W (1); Worker-bin-4.5.5; Worker-con-4.4.1-C (Festo 1) -Vine 1_20130620123306

I want to reuse this file / testname I have to close the timestamp, if already One, and add the current timestamp. This is what I have so far received:

  for one more run # test testname = testname = get-content "output \ testname" - host old: $ testname #strip date Testname = $ testname.Substring (0, $ string.Length - 14) $ olddate = $ testname.Substring ($ string.Length - 14) from testname, type-host Old Date: $ old date #add new date $ startTime = Get a date-format yyyyMMDHHmmss $ Testname + = "_" $ testname + = $ startTime - host new: $ testname   

I have a time-stamp / if the last 14 characters are digits How to check How do I break a testname from a string?

this?

  $ filename = "data-c (festo1-small1); divider-bin -1.4.4; divider-con-1.3.3-W (1,16); storage-bin- 1.5.4; Storage-conf-1.5.0-w (1); Worker-bin-4.5.5; Worker-con-4.4.1-C (Festo 1) -Vine 1_20130620123306 "$ filename -replace '\ d { 14} $ '   

No comments:

Post a Comment