Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell选择字符串后,Windows上的txt文件越大,行数越少_Windows_File_Powershell_Size - Fatal编程技术网

Powershell选择字符串后,Windows上的txt文件越大,行数越少

Powershell选择字符串后,Windows上的txt文件越大,行数越少,windows,file,powershell,size,Windows,File,Powershell,Size,我使用Powershell Get Content和-nomatch操作符对文本文件应用了几个过滤器,然后将结果假脱机到一个文件中 gc file.txt | {?_ -notmatch 'excl1|excl2|excl3'} | out-file newfile.txt 结果是输出文件(newfile.txt)的行数较少,但windows报告的行数大于file.txt 有人遇到过这种行为吗?windows如何报告正确的大小?我检查了行数,行数越少的文件越大。我肯定您有编码问题。默认情况下,

我使用Powershell Get Content和-nomatch操作符对文本文件应用了几个过滤器,然后将结果假脱机到一个文件中

gc file.txt | {?_ -notmatch 'excl1|excl2|excl3'} | out-file newfile.txt
结果是输出文件(newfile.txt)的行数较少,但windows报告的行数大于file.txt


有人遇到过这种行为吗?windows如何报告正确的大小?我检查了行数,行数越少的文件越大。

我肯定您有编码问题。默认情况下,
Get Content
使用ascii,而
Out File
使用Unicode

-编码

指定文件中使用的字符编码类型。有效值为“Unicode”、“UTF7”、“UTF8”、“UTF32”、“ASCII”、“BigendiaUnicode”、“Default”和“OEM”“Unicode”是默认值

使用
-Enconding ascii
输出文件
或只使用
设置内容
,因为它是
获取内容
的合作伙伴

Get-Content file.txt | {?_ -notmatch 'excl1|excl2|excl3'} | 
    out-file -Encoding ascii newfile.txt
    # or
    Set-Content newfile.txt

如果您在PowerShell v3及更高版本中的输入文件
Get Content
存在问题,则从另一个方向出发,还支持
-Enconding

使用以下格式的多个关键字过滤文本文件(.txt):gc file.txt |?{$|-notmatch'exc1 | exc2 | exc2'}| out file newfile.txt。newfile.txt比file.txt大{?-notmatch'excl1 | excl2 | excl3}是过滤器。给我们一个示例文件,比较文件大小。。。。还需要知道编码。我猜这就是问题的根源?我同意马特的看法。输出文件可能更大,因为
Out file
使用Unicode编码(每个字符2个字节)创建文件,而输入文件很可能是ASCII编码(每个字符1个字节)。哪里是
Select String