tags:

views:

237

answers:

2

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 but the bottom 16 lines is important for confirmation of package installation.

+2  A: 

The more command can be used to extract the last n lines. If a file, someFile.txt, contains 2000 lines then the last 16 lines can be extracted with:

    more /e +1984 someFile.txt > lastLines.txt

The number of lines in someFile.txt can found as:

    for /f %%i in ('find /v /c "" ^< someFile.txt') do set /a lines=%%i

The call of more then becomes:

    set /a startLine=%lines% - 16
    more /e +%startLine% someFile.txt > lastLines.txt
Peter Mortensen
+1  A: 

You can download DOS ports of most Unix commands (for example here - pick any set of commands you like that includes tail)

After downloading, simply use tail -16 filename.txt

The benefit (to offset the effort of downloading/unpacking) is that you get a whole BUNDLE of really good Unix command line tools to use.

DVK
i recommend the GNU ports http://gnuwin32.sourceforge.net/packages.html
ghostdog74