BAT file to read and copy bottom 16 lines from a text file to another one?

前端 未结 3 2056
庸人自扰
庸人自扰 2020-12-12 02:30

I need to copy the bottom 16 lines from a text file to another text file. I need to do this procedure for all clients. At the client\'s location the text file will be common

3条回答
  •  时光取名叫无心
    2020-12-12 03:10

    The more command can be used to extract the last n lines:

    1. If a file, someFile.txt, contains 2000 lines then the last 16 lines can be extracted with ("/E +n: Start displaying the first file at line n"):

      more /e +1984 someFile.txt > lastLines.txt
      
    2. The number of lines in someFile.txt can found as:

      for /f %%i in ('find /v /c "" ^< someFile.txt') do set /a lines=%%i
      
    3. The call of more then becomes (still for this example, the last 16 lines):

      set /a startLine=%lines% - 16
      more /e +%startLine% someFile.txt > lastLines.txt
      

提交回复
热议问题