I want split using -.

hello

I want help about split function. I want change old.txt like new.txt.
Now I try using %{"$($_.Split("      ")[3,0,1,10,12-50])"}.

old.txt data is below
=============================================================
8/30/2015 21:41:25  XXX2020     EMERGENCY         sysconf.logErr: sysconfig: Adapter blablablabla
8/31/2015 20:41:25  XXX2020     WARNING         cmds.logErr: blablablabla
8/29/2015 11:41:25  XXX2020     ERROR         logErr: sysconfig: Adapter blablablabla
=============================================================

new.txt data is below
=============================================================
XXX2020 8/30/2015 21:41:25 sysconf.logErr: sysconfig: Adapter blablablabla
XXX2020 8/31/2015 20:41:25 cmds.logErr: blablablabla
XXX2020 8/29/2015 11:41:25 logErr: sysconfig: Adapter blablablabla
=============================================================


August 31st, 2015 11:40pm

I would start by splitting at the second group of blanks.

$Split0 = $oldline.split("          ")

$Split1 = $oldline.split(" ")

$newline = "{0} {1} {2} {3}" -f $Split1[2], $Split1[0], Split1[1], $Split0[1]

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 11:53pm

This works for me
$( gc old.txt | 
  %{ 
     $a = $_ -split '\s+',5 
     $a[2]+' '+$a[0]+' '+$a[1]+' '+$a[4] 
   } 
 ) | out-string -stream | out-file new.txt

September 1st, 2015 12:46am

can you make one line command?
Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 12:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics