This powershell code deletes the first 4 lines in the file.

(gc "old.zip" | select -Skip 4) | sc "new.zip" 

But old.zip has the end of lines Unix (LF)

And this code also converts the end of file lines in Windows (CR LF)

How to delete the first 4 lines without converting?

Due to the presence of a lot of "strange" characters in .zip, other ways to delete the first n lines in the .zip file do not work. For example more +4 "old.zip" >"new.zip" in cmd does not work, etc.

Through powershell, it is somehow removed but also not without problems.

Do you know other ways to delete the first n lines in a .zip file?

  • one
    Deletion is performed simply - it is read that the specified is skipped, the rest is written. And when writing, alas, the end of the lines of the file a la Windows (CR LF) is used ... and there are no parameters that control this business in Set-Content. - Akina
  • one
    A zip is a binary format, what kind of lines can we talk about? If your goal is to get a broken zip-archive, then this can be done in more simple ways. - Yaant

2 answers 2

PowerShell:

 (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))); 

If the file is really text, then you need to work with it as with text. And if this is a real zip-archive, then you are trying to do something strange.

  • Thanks, I just needed the shortest version - SlimeSli

I use csc.exe - c # compiler to solve this

Copy by .zip whithout first i symbols, where the text is in line.

 using System; using System.IO; using System.Linq; namespace ConsoleApplication8 { internal static class Program { public static void Main(string[] args) { var i = File.ReadAllText("C:\\MyFolder\\old.zip") .IndexOf("="+"183290132"+"=", StringComparison.Ordinal); var zipFolder = File.ReadAllBytes("C:\\MyFolder\\old.zip") .Skip(i+20).ToArray(); File.WriteAllBytes("C:\\MyFolder\\new.zip", zipFolder); } } } 
  • It is curious why you asked the question in Russian, and answered it in English? - tutankhamun
  • I created a copy of the question in English stackoverflow - SlimeSli