Do you know how to use powershell to move column DocumentNo to last column ?
| D|Ref.Doc. |Row|DocumentNo |CoCd|Pstng Date
| W|5007534739| 1|65713191 |STCD|01/17/2016
| W|5007534739| 1|65713191 |STCD|01/17/2016
| W|5007534739| 1|65713191 |STCD|01/17/2016
Expected output
| D|Ref.Doc. |Row|CoCd|Pstng Date|DocumentNo
| W|5007534739| 1|STCD|01/17/2016|65713191
| W|5007534739| 1|STCD|01/17/2016|65713191
| W|5007534739| 1|STCD|01/17/2016|65713191
Here the command that I've tried
(get-content $file -ReadCount 0) |
foreach {
'{0}|{1}|{2}|{3}|{5}|{6}|{4}' -f $_.split('|')
} | Set-Content $file2
The code works properly, but in case DocumentNo containt a pipe as data, how to handle it ?
% {$Match=[System.Text.RegularExpressions.Match]::Empty} {if(-not $Match.Success) {$Match=[Regex]::Match($_,'\|DocumentNo\s*(?=\|)')} $_.Remove($Match.Index,$Match.Length) + $_.Substring($Match.Index,$Match.Length)}