Is there a way to simulate the *nix tail command on the Windows command line? I have a file and I want a way to snip off the first n lines of text. For example:
you can also use Git bash where head and tail are emulated as well
Get-content -Tail n file.txt
with powershell is the only thing that comes close to tail
in linux.
The Get-Content *filename* | Select-Object -last *n*
suggested above loads/parse the whole thing. Needless to say, it was not happy with my 10GB log file... The -Tail
option does start by the end of the file.
No exact equivalent. However there exist a native DOS command "more" that has a +n option that will start outputting the file after the nth line:
DOS Prompt:
C:\>more +2 myfile.txt
The above command will output everything after the first 2 lines.
This is actually the inverse of Unix head:
Unix console:
root@server:~$ head -2 myfile.txt
The above command will print only the first 2 lines of the file.
You could get CoreUtils from GnuWin32, which is a collection of standard unix tools, ported to Windows.
It, among other things, contains head.
This is a total hack but if it's a huge file that you want to just examine the format, header, etc. and you're looking for a solution you can always just redirect the 'more' output to a new file and CTRL-C quickly. The output rows can't be controlled precisely and you will most likely kill it in the middle of a line of output but it's a cheap way of grabbing a small bit of an otherwise unusable file.
Ex.
C:\more test.csv > test.txt
^C C:\more test.txt
line 1
line 2
etc...... C:\
Warning, using the batch file for, tokens, and delims capability on unknown text input can be a disaster due to the special interpretation of chars like &, !, <, etc. Such methods should be reserved for only predictable text.