开发者

Powershell and getcontent CR LF

开发者 https://www.devze.com 2022-12-15 23:54 出处:网络
Have a very simple powershell script to count the number of trades in a file: (gc \\\\mimkeimc11n\\Batch\\FundQuest\\TradeFiles\\trades.dat |? {$_ -match \'SL|BY\'} | Measure-Object | select count).c

Have a very simple powershell script to count the number of trades in a file:

(gc \\mimkeimc11n\Batch\FundQuest\TradeFiles\trades.dat |? {$_ -match 'SL|BY'} | Measure-Object | select count).count > \\mimkeimc11n\Batch\FundQuest\ConfirmtoFQ\NumberofTrades.txt

The problem I am running into is the output NumberofTrades.txt is including the number that I want, but also a CR LF, not sure why??开发者_如何学Python? Any help would be greatly appreciated.

Powershell and getcontent CR LF

http://screencast.com/t/MGM3ZTc0Mzct


PowerShell is pretty persistent about outputting newlines for you when you send strings to Out-File (alias >) or even Add/Set-Content. It can be infuriating sometimes and makes me wish for a -NoNewLine parameter on these cmdlets. For now you can use a .NET API e.g.:

$path = '\mimkeimc11n\Batch\FundQuest\ConfirmtoFQ\NumberofTrades.txt'
(gc \mimkeimc11n\Batch\FundQuest\TradeFiles\trades.dat | 
    ?{$_ -match 'SL|BY'} | Measure-Object).count |
 %{[IO.File]::WriteAllText($path, $_)}
0

精彩评论

暂无评论...
验证码 换一张
取 消