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.
http://screencast.com/t/MGM3ZTc0MzctPowerShell 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, $_)}
精彩评论