排序文件的大小是Powershell中原始文件大小的两倍 [英] Size of the sorted file is double than original file in powershell

查看:114
本文介绍了排序文件的大小是Powershell中原始文件大小的两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Powershell脚本,可以读取文件内容,对其进行排序并将输出写入新文件.以下是脚本:

I have a powershell script, that reads file content, sorts it and writes output to new file. Following is the script:

获取内容$ inputFile | sort> $ sortedFile

get-content $inputFile | sort > $sortedFile

文件中的输出已正确排序,但是输出文件($ sortedFile)的大小是输入文件($ inputFile)的两倍.注意:输出文件中没有重复或多余的行.

The output in file is sorted properly, but the output file ($sortedFile) is double larger than input file ($inputFile). Note: There are no duplicate or extra line in output file.

任何有关此的帮助或想法都会有所帮助.

Any help or ideas regarding this will be helpful.

推荐答案

输入文件很可能是ascii编码,而使用重定向的默认输出是unicode编码.

Most likely the input file is ascii encoding while the default output using redirection is unicode encoding.

您可以使用输出文件,而不是使用>进行重定向并指定一种编码.

Instead of using > as redirection you can use out-file and specify an encoding.

get-content $inputFile | sort | out-file -encoding ASCII

这篇关于排序文件的大小是Powershell中原始文件大小的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆