[英]Delete first n lines in file (.zip file with many "strange" symbols)
此 powershell 代碼刪除文件中的前 4 行
(gc "old.zip" | select -Skip 4) | sc "new.zip"
但是old.zip
文件有Unix (LF)行結尾
並且此代碼還將文件行結尾轉換為Windows (CR LF)
如何在不轉換的情況下刪除前 4 行?
由於.zip 中存在許多“奇怪”符號,因此刪除 .zip 文件中前 n 行的其他方法不起作用。 例如, cmd
中more than +4 "old.zip"> "new.zip"
不起作用等。
通過powershell,類似的東西被刪除了,但也不是沒有問題。
您知道刪除.zip文件中前 n 行的其他方法嗎?
像這樣的東西?
$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
電源外殼:
(gc "old.txt" | select -Skip 4 | Out-String) -replace "`r`n", "`n" | Out-File "new.txt"
C#:
File.WriteAllText("new.txt", string.Join("\n", File.ReadLines("old.txt").Skip(4)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.