3

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?

1
  • get-content inFILE | select-string "string" | set-string outFILE was effective in eliminating carriage returns from my output. Commented Nov 22, 2011 at 18:17

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

In case anyone is curious... This happens because > is an alias to Out-File, and Out-File, by default, truncates content @ 80 Characters. You can change this with | Out-File -Width $n, but at that point, you're not using the redirection operator. Out-String also does something similar.
0

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

Comments

0

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).

1 Comment

Try to avoid answering the same question twice. You should rather update previous answer to keep threads clean and not turning them into chat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.