Windows equivalent of the 'tail' command

前端 未结 21 2947
长情又很酷
长情又很酷 2020-11-28 01:48

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:

相关标签:
21条回答
  • 2020-11-28 02:34
    more /e filename.txt P n
    

    where n = the number of rows to display. Works fast and is exactly like head command.

    0 讨论(0)
  • 2020-11-28 02:34
    set /p line= < file.csv 
    echo %line%
    

    it will return first line of your file in cmd Windows in variable %line%.

    0 讨论(0)
  • 2020-11-28 02:36

    When using more +n that Matt already mentioned, to avoid pauses in long files, try this:

    more +1 myfile.txt > con

    When you redirect the output from more, it doesn't pause - and here you redirect to the console. You can similarly redirect to some other file like this w/o the pauses of more if that's your desired end result. Use > to redirect to file and overwrite it if it already exists, or >> to append to an existing file. (Can use either to redirect to con.)

    0 讨论(0)
  • 2020-11-28 02:36

    If you want the head command, one easy way to get it is to install Cygwin. Then you'll have all the UNIX tools at your disposal.

    If that isn't a good solution, then you can try using findstr and do a search for the end-of-line indicator.

    findstr on MSDN: http://technet.microsoft.com/en-us/library/bb490907.aspx

    0 讨论(0)
  • 2020-11-28 02:36

    I have not tried extracting a range, but I was able to get a line using the following DOS command:

    find /N " " *.log|find "[6]" 
    

    Since most files contain spaces, this command pulls every line from all LOG files and basically numbers them starting from 1 for each file. The numbered results are then piped into the second FIND command which looks for the line tagged as number 6.

    0 讨论(0)
  • 2020-11-28 02:36

    There's a free head utility on this page that you can use. I haven't tried it yet.

    0 讨论(0)
提交回复
热议问题