Question

I have a file that contains like 200 pipes with data in between some of them and others are consecutive pipes. File line looks like this.

|08|6|6|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||02|||||||Z4|2014-04-02 15:49:58|04|001|01|***|PMER|***|***|2013-08-01|||||||||||||||||

I have this powershell script to handle the exclusion of the last several pipes:

gc .\oauthrn.cms|% {$a=@();$b="";$a+=$_.split('|'); for ($i=0;$i -lt 168; $i++) {$b+=$a[$i]+'|'} $b}|out-file "H:\Documentation\Scripts\Pipe Delimiter Project\shineynewfile.txt"

Turns that fileline into this...(there are several of these lines in one file)

|08|6|6|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||02|||||||Z4|2014-04-02 15:49:58|04|001|01|***|PMER|***|***|2013-08-01|

The last step is to trim the last pipe off the end of the each line but keep the date in there... any suggestions on how I can achieve this?

Thanks in advance

Était-ce utile?

La solution

Try this out instead:

gc .\oauthrn.cms|%{$_.TrimEnd("|")}|out-file .\ShineyNewFile.txt

That trims all "|" characters off the end of each line.

Autres conseils

Do something like below

(Get-Content c:\test.txt) | 
ForEach-Object {$_ -replace '$\|', ''} |
Set-Content c:\test.txt
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top