[英]Delete first n lines in file (.zip file with many "strange" symbols)
This powershell code delete first 4 lines in file此 powershell 代码删除文件中的前 4 行
(gc "old.zip" | select -Skip 4) | sc "new.zip"
But old.zip
file has Unix (LF) line endings但是
old.zip
文件有Unix (LF)行结尾
And this code also converts file line endings to Windows (CR LF)并且此代码还将文件行结尾转换为Windows (CR LF)
How to delete first 4 lines without converting ?
如何在不转换的情况下删除前 4 行?
Because of the presence of many "strange" symbols in .zip , other ways to remove the first n lines in a .zip file do not work.由于.zip 中存在许多“奇怪”符号,因此删除 .zip 文件中前 n 行的其他方法不起作用。 For example,
more than +4 "old.zip"> "new.zip"
in cmd
does not work, etc.例如,
cmd
中more than +4 "old.zip"> "new.zip"
不起作用等。
Through powershell something like it is removed but also not without problems.通过powershell,类似的东西被删除了,但也不是没有问题。
Do you know other ways to remove the first n lines in a .zip file ?
您知道删除.zip文件中前 n 行的其他方法吗?
somthing like this?像这样的东西?
$PathZipFile="c:\temp\File_1.zip"
$NewPathZipFile="c:\temp\NewFile_1.zip"
#create temporary directory name
$TemporyDir=[System.IO.Path]::Combine("c:\temp", [System.IO.Path]::GetRandomFileName())
#extract archive into temporary directory
Expand-Archive "c:\temp\File_1.zip" -DestinationPath $TemporyDir
#loop file for remove 4 first lines for every files and compress in new archive
Get-ChildItem $TemporyDir -file | %{
(Get-Content $_.FullName | select -Skip 4) | Set-Content -Path $_.FullName;
Compress-Archive $_.FullName $NewPathZipFile -Update
}
Remove-Item $TemporyDir -Recurse -Force
PowerShell:电源外壳:
(gc "old.txt" | select -Skip 4 | Out-String) -replace "`r`n", "`n" | Out-File "new.txt"
C#: C#:
File.WriteAllText("new.txt", string.Join("\n", File.ReadLines("old.txt").Skip(4)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.