programing

PowerShell:Out-File은 왜 긴 줄을 더 작은 줄로 나누나요?

minimums 2023. 8. 11. 21:37
반응형

PowerShell:Out-File은 왜 긴 줄을 더 작은 줄로 나누나요?

이 작은 실험을 해보세요.파일 만들기Foo.txt다음과 같은 매우 긴 텍스트 행(500자로 표시):

// Foo.txt
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

이제 다음 명령을 실행합니다.

$ Get-Content Foo.txt | Select-String "a" | Out-File Foo2.txt

당신은 긴 줄이 작은 줄로 분해된 것을 발견할 것입니다.Foo2.txt각 작은 줄의 길이는 콘솔 너비와 동일합니다.

출력이 콘솔로 향하지 않을 때 Out-File이 긴 줄을 더 작은 줄로 나누는 이유는 무엇입니까?

그리고 왜 Out-File은 다음 명령에 대한 줄을 구분하지 않습니까?

$ Get-Content Foo.txt | Out-File Foo3.txt

-width 매개변수를 사용하여 Out-File의 줄 바꿈 위치를 조정할 수 있습니다.

$ Get-Content Foo.txt | Select-String "a" | Out-File -width 1000 Foo2.txt
$ Get-Content Foo.txt | Select-String "a" | Add-Content Foo2.txt

사용하다Add-Content(또는 사용할 수 있음)Set-Content파일을 덮어쓰려는 경우).

이것은 의 결과로 설명될 수 있습니다.Get-Content Foo.txt | Select-String "a"유형의MatchInfo그것은 아닙니다.string.

그냥 테스트:

Get-Content Foo.txt | Select-String "a" | Format-list *

언급URL : https://stackoverflow.com/questions/9528039/powershell-why-does-out-file-break-long-line-into-smaller-lines

반응형