[MSH] How to emulate 'tail'

Discussion in 'Scripting' started by forestial, Feb 1, 2006.

  1. forestial

    forestial Guest

    The get-content cmdlet can emulate the unix 'head' command:

    get-content -TotalCount 10 abc.txt

    produces the first 10 lines of the file.

    Is there a way to emulate 'tail'?

    Better yet, how about 'tail -f' (which keeps watching the file, outputting
    any new information added to the end of it) - very useful for keeping an eye
    on log files.
     
    forestial, Feb 1, 2006
    #1
    1. Advertisements

  2. Hi,

    You can use the last parameter with select-object.

    For example,

    get-process | sort-object handlecount | select -last 10

    should work.

    Andrew Watt
    MVP
     
    Andrew Watt [MVP], Feb 1, 2006
    #2
    1. Advertisements

  3. forestial

    forestial Guest

    Thanks. This nicely solves the basic tail functionality.

    Any ideas on the 'tail -f' variant? Seems that it would require some kind
    of option to get-content but I don't see anything that looks like it.
     
    forestial, Feb 1, 2006
    #3
  4. Hi,

    The thread has become split. In the part without the [MSH] header a
    couple of people have made suggestions for functionality like tail -f.

    Andrew Watt
    MVP
     
    Andrew Watt [MVP], Feb 1, 2006
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.