chrips
chrips

Reputation: 5276

Powershell - Carriage returns inserted in output when I use '>'

How do I stop this command from dumping carriage returns into my output:

get-content inFILE | select-string "string" > outFILE

Text that was non-wrapped or lacking carriage return suddenly has a carriage return at the 80th character per line. Is there a directive I can use to stop it from doing this to my output?

Upvotes: 3

Views: 4046

Answers (3)

Rolf
Rolf

Reputation: 1

Ok - Found that using the -width parameter for out-file resolves this. It also confirms my observation regarding the window/buffer size affecting the output. -Width Specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped. If you omit this parameter, the width is determined by the characteristics of the host. The default for the Windows PowerShell console is 80 (characters).

Upvotes: 0

Rolf
Rolf

Reputation: 1

My experience is that the location of the inserted CR/LF is based on the buffer or window size of the PowerShell window - When I change the values the location of the CR/LF changes so it doesn't seem to be based on the default of 80. Using the suggested > rather than out-file didn't change the behavior.

Get-ChildItem calllogs -Filter "*-log" -Recurse | Select-string -Pattern "SWIRcnd" > "C:\temp\RecResults3.txt"

Name Value ---- ----- PSVersion 3.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.18444 BuildVersion 6.2.9200.16398 PSCompatibleVersions {1.0, 2.0, 3.0} PSRemotingProtocolVersion 2.2

Upvotes: 0

manojlds
manojlds

Reputation: 301047

Use set-content instead of > ( which is same as out-file)

Upvotes: 5

Related Questions