Search code examples
cmdmovelines

How to cut the first line and paste it on new file with CMD


I want move the first 2 lines from one file to one other. Does anyone knows how? file1.txt > file2.txt


Solution

  • setlocal enabledelayedexpansion
    set "count=2"
    <file1.txt (
      for /l %%i in (1,1,%count%) do (
        set "line="
        set /p "line="
        echo/!line!
      )
    ) >file2.txt
    more +2 file1.txt > file3.txt
    del file1.txt
    ren file3.txt file1.txt