Last Updated: February 25, 2016
·
805
· nuck

Tail/head by screenfuls in zsh

It's often a lot easier to think in terms of "I want half a screen" than "I want 30 lines" so I wrote some aliases to wrap tail & head into this case.

Code

# Tail/head by screenfuls, via zsh function.
# Yay zshell~
stail () {
    # Use zsh's arithmetic substitution to do the math
    # then cast to an integer to round it off
    integer l=$(($LINES * $1))
    tail -n$l $2
}
shead () {
    # Use zsh's arithmetic substitution to do the math
    # then cast to an integer to round it off
    integer l=$(($LINES * $1))
    head -n$l $2
}

Usage

# half a screenful, tail
$ stail 0.5 file
# two screenfuls, head
$ shead 2 file

Idea from https://twitter.com/seb_m/status/365185187996368896